home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources / function.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  147.8 KB  |  4,753 lines  |  [TEXT/MPS ]

  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2.    Copyright (C) 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file handles the generation of rtl code from tree structure
  22.    at the level of the function as a whole.
  23.    It creates the rtl expressions for parameters and auto variables
  24.    and has full responsibility for allocating stack slots.
  25.  
  26.    `expand_function_start' is called at the beginning of a function,
  27.    before the function body is parsed, and `expand_function_end' is
  28.    called after parsing the body.
  29.  
  30.    Call `assign_stack_local' to allocate a stack slot for a local variable.
  31.    This is usually done during the RTL generation for the function body,
  32.    but it can also be done in the reload pass when a pseudo-register does
  33.    not get a hard register.
  34.  
  35.    Call `put_var_into_stack' when you learn, belatedly, that a variable
  36.    previously given a pseudo-register must in fact go in the stack.
  37.    This function changes the DECL_RTL to be a stack slot instead of a reg
  38.    then scans all the RTL instructions so far generated to correct them.  */
  39.  
  40. #include "config.h"
  41.  
  42. #include <stdio.h>
  43.  
  44. #include "rtl.h"
  45. #include "tree.h"
  46. #include "flags.h"
  47. #include "function.h"
  48. #include "insn-flags.h"
  49. #include "expr.h"
  50. #include "insn-codes.h"
  51. #include "regs.h"
  52. #include "hard-reg-set.h"
  53. #include "insn-config.h"
  54. #include "recog.h"
  55. #include "output.h"
  56. #include "basic-block.h"
  57.  
  58. /* Pointer to the current function's calling convention.
  59.    NULL if no special calling convention is defined. */
  60.  
  61. char *current_function_call_convention;
  62.  
  63. /* Nonzero if the current function is declared pascal. */
  64.  
  65. int current_function_is_pascal;
  66.  
  67. /* Round a value to the lowest integer less than it that is a multiple of
  68.    the required alignment.  Avoid using division in case the value is
  69.    negative.  Assume the alignment is a power of two.  */
  70. #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
  71.  
  72. /* Similar, but round to the next highest integer that meets the
  73.    alignment.  */
  74. #define CEIL_ROUND(VALUE,ALIGN)    (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
  75.  
  76. /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
  77.    during rtl generation.  If they are different register numbers, this is
  78.    always true.  It may also be true if
  79.    FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
  80.    generation.  See fix_lexical_addr for details.  */
  81.  
  82. #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  83. #define NEED_SEPARATE_AP
  84. #endif
  85.  
  86. /* Number of bytes of args popped by function being compiled on its return.
  87.    Zero if no bytes are to be popped.
  88.    May affect compilation of return insn or of function epilogue.  */
  89.  
  90. int current_function_pops_args;
  91.  
  92. /* Nonzero if function being compiled needs to be given an address
  93.    where the value should be stored.  */
  94.  
  95. int current_function_returns_struct;
  96.  
  97. /* Nonzero if function being compiled needs to
  98.    return the address of where it has put a structure value.  */
  99.  
  100. int current_function_returns_pcc_struct;
  101.  
  102. /* Nonzero if function being compiled needs to be passed a static chain.  */
  103.  
  104. int current_function_needs_context;
  105.  
  106. /* Nonzero if function being compiled can call setjmp.  */
  107.  
  108. int current_function_calls_setjmp;
  109.  
  110. /* Nonzero if function being compiled can call longjmp.  */
  111.  
  112. int current_function_calls_longjmp;
  113.  
  114. /* Nonzero if function being compiled receives nonlocal gotos
  115.    from nested functions.  */
  116.  
  117. int current_function_has_nonlocal_label;
  118.  
  119. /* Nonzero if function being compiled contains nested functions.  */
  120.  
  121. int current_function_contains_functions;
  122.  
  123. /* Nonzero if function being compiled can call alloca,
  124.    either as a subroutine or builtin.  */
  125.  
  126. int current_function_calls_alloca;
  127.  
  128. /* Nonzero if the current function returns a pointer type */
  129.  
  130. int current_function_returns_pointer;
  131.  
  132. /* If some insns can be deferred to the delay slots of the epilogue, the
  133.    delay list for them is recorded here.  */
  134.  
  135. rtx current_function_epilogue_delay_list;
  136.  
  137. /* If function's args have a fixed size, this is that size, in bytes.
  138.    Otherwise, it is -1.
  139.    May affect compilation of return insn or of function epilogue.  */
  140.  
  141. int current_function_args_size;
  142.  
  143. /* # bytes the prologue should push and pretend that the caller pushed them.
  144.    The prologue must do this, but only if parms can be passed in registers.  */
  145.  
  146. int current_function_pretend_args_size;
  147.  
  148. /* # of bytes of outgoing arguments required to be pushed by the prologue.
  149.    If this is non-zero, it means that ACCUMULATE_OUTGOING_ARGS was defined
  150.    and no stack adjusts will be done on function calls.  */
  151.  
  152. int current_function_outgoing_args_size;
  153.  
  154. /* This is the offset from the arg pointer to the place where the first
  155.    anonymous arg can be found, if there is one.  */
  156.  
  157. rtx current_function_arg_offset_rtx;
  158.  
  159. /* Nonzero if current function uses varargs.h or equivalent.
  160.    Zero for functions that use stdarg.h.  */
  161.  
  162. int current_function_varargs;
  163.  
  164. /* Quantities of various kinds of registers
  165.    used for the current function's args.  */
  166.  
  167. CUMULATIVE_ARGS current_function_args_info;
  168.  
  169. /* Name of function now being compiled.  */
  170.  
  171. char *current_function_name;
  172.  
  173. /* If non-zero, an RTL expression for that location at which the current
  174.    function returns its result.  Always equal to
  175.    DECL_RTL (DECL_RESULT (current_function_decl)), but provided
  176.    independently of the tree structures.  */
  177.  
  178. rtx current_function_return_rtx;
  179.  
  180. /* Nonzero if the current function uses the constant pool.  */
  181.  
  182. int current_function_uses_const_pool;
  183.  
  184. /* Nonzero if the current function uses pic_offset_table_rtx.  */
  185. int current_function_uses_pic_offset_table;
  186.  
  187. /* The arg pointer hard register, or the pseudo into which it was copied.  */
  188. rtx current_function_internal_arg_pointer;
  189.  
  190. /* The FUNCTION_DECL for an inline function currently being expanded.  */
  191. tree inline_function_decl;
  192.  
  193. /* Number of function calls seen so far in current function.  */
  194.  
  195. int function_call_count;
  196.  
  197. /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
  198.    (labels to which there can be nonlocal gotos from nested functions)
  199.    in this function.  */
  200.  
  201. tree nonlocal_labels;
  202.  
  203. /* RTX for stack slot that holds the current handler for nonlocal gotos.
  204.    Zero when function does not have nonlocal labels.  */
  205.  
  206. rtx nonlocal_goto_handler_slot;
  207.  
  208. /* RTX for stack slot that holds the stack pointer value to restore
  209.    for a nonlocal goto.
  210.    Zero when function does not have nonlocal labels.  */
  211.  
  212. rtx nonlocal_goto_stack_level;
  213.  
  214. /* Label that will go on parm cleanup code, if any.
  215.    Jumping to this label runs cleanup code for parameters, if
  216.    such code must be run.  Following this code is the logical return label.  */
  217.  
  218. rtx cleanup_label;
  219.  
  220. /* Label that will go on function epilogue.
  221.    Jumping to this label serves as a "return" instruction
  222.    on machines which require execution of the epilogue on all returns.  */
  223.  
  224. rtx return_label;
  225.  
  226. /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
  227.    So we can mark them all live at the end of the function, if nonopt.  */
  228. rtx save_expr_regs;
  229.  
  230. /* List (chain of EXPR_LISTs) of all stack slots in this function.
  231.    Made for the sake of unshare_all_rtl.  */
  232. rtx stack_slot_list;
  233.  
  234. /* Chain of all RTL_EXPRs that have insns in them.  */
  235. tree rtl_expr_chain;
  236.  
  237. /* Label to jump back to for tail recursion, or 0 if we have
  238.    not yet needed one for this function.  */
  239. rtx tail_recursion_label;
  240.  
  241. /* Place after which to insert the tail_recursion_label if we need one.  */
  242. rtx tail_recursion_reentry;
  243.  
  244. /* Location at which to save the argument pointer if it will need to be
  245.    referenced.  There are two cases where this is done: if nonlocal gotos
  246.    exist, or if vars stored at an offset from the argument pointer will be
  247.    needed by inner routines.  */
  248.  
  249. rtx arg_pointer_save_area;
  250.  
  251. /* Offset to end of allocated area of stack frame.
  252.    If stack grows down, this is the address of the last stack slot allocated.
  253.    If stack grows up, this is the address for the next slot.  */
  254. int frame_offset;
  255.  
  256. /* List (chain of TREE_LISTs) of static chains for containing functions.
  257.    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
  258.    in an RTL_EXPR in the TREE_VALUE.  */
  259. static tree context_display;
  260.  
  261. /* List (chain of TREE_LISTs) of trampolines for nested functions.
  262.    The trampoline sets up the static chain and jumps to the function.
  263.    We supply the trampoline's address when the function's address is requested.
  264.  
  265.    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
  266.    in an RTL_EXPR in the TREE_VALUE.  */
  267. static tree trampoline_list;
  268.  
  269. /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
  270. static rtx parm_birth_insn;
  271.  
  272. #if 0
  273. /* Nonzero if a stack slot has been generated whose address is not
  274.    actually valid.  It means that the generated rtl must all be scanned
  275.    to detect and correct the invalid addresses where they occur.  */
  276. static int invalid_stack_slot;
  277. #endif
  278.  
  279. /* Last insn of those whose job was to put parms into their nominal homes.  */
  280. static rtx last_parm_insn;
  281.  
  282. /* 1 + last pseudo register number used for loading a copy
  283.    of a parameter of this function.  */
  284. static int max_parm_reg;
  285.  
  286. /* Vector indexed by REGNO, containing location on stack in which
  287.    to put the parm which is nominally in pseudo register REGNO,
  288.    if we discover that that parm must go in the stack.  */
  289. static rtx *parm_reg_stack_loc;
  290.  
  291. #if 0  /* Turned off because 0 seems to work just as well.  */
  292. /* Cleanup lists are required for binding levels regardless of whether
  293.    that binding level has cleanups or not.  This node serves as the
  294.    cleanup list whenever an empty list is required.  */
  295. static tree empty_cleanup_list;
  296. #endif
  297.  
  298. /* Nonzero once virtual register instantiation has been done.
  299.    assign_stack_local uses frame_pointer_rtx when this is nonzero.  */
  300. static int virtuals_instantiated;
  301.  
  302. /* Nonzero if we need to distinguish between the return value of this function
  303.    and the return value of a function called by this function.  This helps
  304.    integrate.c  */
  305.  
  306. extern int rtx_equal_function_value_matters;
  307.  
  308. void fixup_gotos ();
  309.  
  310. static tree round_down ();
  311. static rtx round_trampoline_addr ();
  312. static rtx fixup_stack_1 ();
  313. static void fixup_var_refs ();
  314. static void fixup_var_refs_insns ();
  315. static void fixup_var_refs_1 ();
  316. static void optimize_bit_field ();
  317. static void instantiate_decls ();
  318. static void instantiate_decls_1 ();
  319. static void instantiate_decl ();
  320. static int instantiate_virtual_regs_1 ();
  321. static rtx fixup_memory_subreg ();
  322. static rtx walk_fixup_memory_subreg ();
  323.  
  324. /* In order to evaluate some expressions, such as function calls returning
  325.    structures in memory, we need to temporarily allocate stack locations.
  326.    We record each allocated temporary in the following structure.
  327.  
  328.    Associated with each temporary slot is a nesting level.  When we pop up
  329.    one level, all temporaries associated with the previous level are freed.
  330.    Normally, all temporaries are freed after the execution of the statement
  331.    in which they were created.  However, if we are inside a ({...}) grouping,
  332.    the result may be in a temporary and hence must be preserved.  If the
  333.    result could be in a temporary, we preserve it if we can determine which
  334.    one it is in.  If we cannot determine which temporary may contain the
  335.    result, all temporaries are preserved.  A temporary is preserved by
  336.    pretending it was allocated at the previous nesting level.
  337.  
  338.    Automatic variables are also assigned temporary slots, at the nesting
  339.    level where they are defined.  They are marked a "kept" so that
  340.    free_temp_slots will not free them.  */
  341.  
  342. struct temp_slot
  343. {
  344.   /* Points to next temporary slot.  */
  345.   struct temp_slot *next;
  346.   /* The rtx to used to reference the slot. */
  347.   rtx slot;
  348.   /* The size, in units, of the slot.  */
  349.   int size;
  350.   /* Non-zero if this temporary is currently in use.  */
  351.   char in_use;
  352.   /* Nesting level at which this slot is being used.  */
  353.   int level;
  354.   /* Non-zero if this should survive a call to free_temp_slots.  */
  355.   int keep;
  356. };
  357.  
  358. /* List of all temporaries allocated, both available and in use.  */
  359.  
  360. struct temp_slot *temp_slots;
  361.  
  362. /* Current nesting level for temporaries.  */
  363.  
  364. int temp_slot_level;
  365.  
  366. /* Pointer to chain of `struct function' for containing functions.  */
  367. struct function *outer_function_chain;
  368.  
  369. /* Given a function decl for a containing function,
  370.    return the `struct function' for it.  */
  371.  
  372. struct function *
  373. find_function_data (decl)
  374.      tree decl;
  375. {
  376.   struct function *p;
  377.   for (p = outer_function_chain; p; p = p->next)
  378.     if (p->decl == decl)
  379.       return p;
  380.   abort ();
  381. }
  382.  
  383. /* Save the current context for compilation of a nested function.
  384.    This is called from language-specific code.
  385.    The caller is responsible for saving any language-specific status,
  386.    since this function knows only about language-independent variables.  */
  387.  
  388. void
  389. push_function_context ()
  390. {
  391.   struct function *p = (struct function *) xmalloc (sizeof (struct function));
  392.  
  393.   p->next = outer_function_chain;
  394.   outer_function_chain = p;
  395.  
  396.   p->name = current_function_name;
  397.   p->decl = current_function_decl;
  398.   p->pops_args = current_function_pops_args;
  399.   p->returns_struct = current_function_returns_struct;
  400.   p->returns_pcc_struct = current_function_returns_pcc_struct;
  401.   p->needs_context = current_function_needs_context;
  402.   p->calls_setjmp = current_function_calls_setjmp;
  403.   p->calls_longjmp = current_function_calls_longjmp;
  404.   p->calls_alloca = current_function_calls_alloca;
  405.   p->has_nonlocal_label = current_function_has_nonlocal_label;
  406.   p->args_size = current_function_args_size;
  407.   p->pretend_args_size = current_function_pretend_args_size;
  408.   p->arg_offset_rtx = current_function_arg_offset_rtx;
  409.   p->uses_const_pool = current_function_uses_const_pool;
  410.   p->uses_pic_offset_table = current_function_uses_pic_offset_table;
  411.   p->internal_arg_pointer = current_function_internal_arg_pointer;
  412.   p->max_parm_reg = max_parm_reg;
  413.   p->parm_reg_stack_loc = parm_reg_stack_loc;
  414.   p->outgoing_args_size = current_function_outgoing_args_size;
  415.   p->return_rtx = current_function_return_rtx;
  416.   p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
  417.   p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
  418.   p->nonlocal_labels = nonlocal_labels;
  419.   p->cleanup_label = cleanup_label;
  420.   p->return_label = return_label;
  421.   p->save_expr_regs = save_expr_regs;
  422.   p->stack_slot_list = stack_slot_list;
  423.   p->parm_birth_insn = parm_birth_insn;
  424.   p->frame_offset = frame_offset;
  425.   p->tail_recursion_label = tail_recursion_label;
  426.   p->tail_recursion_reentry = tail_recursion_reentry;
  427.   p->arg_pointer_save_area = arg_pointer_save_area;
  428.   p->rtl_expr_chain = rtl_expr_chain;
  429.   p->last_parm_insn = last_parm_insn;
  430.   p->context_display = context_display;
  431.   p->trampoline_list = trampoline_list;
  432.   p->function_call_count = function_call_count;
  433.   p->temp_slots = temp_slots;
  434.   p->temp_slot_level = temp_slot_level;
  435.   p->fixup_var_refs_queue = 0;
  436.   p->epilogue_delay_list = current_function_epilogue_delay_list;
  437.  
  438.   save_tree_status (p);
  439.   save_storage_status (p);
  440.   save_emit_status (p);
  441.   init_emit ();
  442.   save_expr_status (p);
  443.   save_stmt_status (p);
  444.   save_varasm_status (p);
  445. }
  446.  
  447. /* Restore the last saved context, at the end of a nested function.
  448.    This function is called from language-specific code.  */
  449.  
  450. void
  451. pop_function_context ()
  452. {
  453.   struct function *p = outer_function_chain;
  454.  
  455.   outer_function_chain = p->next;
  456.  
  457.   current_function_name = p->name;
  458.   current_function_decl = p->decl;
  459.   current_function_pops_args = p->pops_args;
  460.   current_function_returns_struct = p->returns_struct;
  461.   current_function_returns_pcc_struct = p->returns_pcc_struct;
  462.   current_function_needs_context = p->needs_context;
  463.   current_function_calls_setjmp = p->calls_setjmp;
  464.   current_function_calls_longjmp = p->calls_longjmp;
  465.   current_function_calls_alloca = p->calls_alloca;
  466.   current_function_has_nonlocal_label = p->has_nonlocal_label;
  467.   current_function_contains_functions = 1;
  468.   current_function_args_size = p->args_size;
  469.   current_function_pretend_args_size = p->pretend_args_size;
  470.   current_function_arg_offset_rtx = p->arg_offset_rtx;
  471.   current_function_uses_const_pool = p->uses_const_pool;
  472.   current_function_uses_pic_offset_table = p->uses_pic_offset_table;
  473.   current_function_internal_arg_pointer = p->internal_arg_pointer;
  474.   max_parm_reg = p->max_parm_reg;
  475.   parm_reg_stack_loc = p->parm_reg_stack_loc;
  476.   current_function_outgoing_args_size = p->outgoing_args_size;
  477.   current_function_return_rtx = p->return_rtx;
  478.   nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
  479.   nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
  480.   nonlocal_labels = p->nonlocal_labels;
  481.   cleanup_label = p->cleanup_label;
  482.   return_label = p->return_label;
  483.   save_expr_regs = p->save_expr_regs;
  484.   stack_slot_list = p->stack_slot_list;
  485.   parm_birth_insn = p->parm_birth_insn;
  486.   frame_offset = p->frame_offset;
  487.   tail_recursion_label = p->tail_recursion_label;
  488.   tail_recursion_reentry = p->tail_recursion_reentry;
  489.   arg_pointer_save_area = p->arg_pointer_save_area;
  490.   rtl_expr_chain = p->rtl_expr_chain;
  491.   last_parm_insn = p->last_parm_insn;
  492.   context_display = p->context_display;
  493.   trampoline_list = p->trampoline_list;
  494.   function_call_count = p->function_call_count;
  495.   temp_slots = p->temp_slots;
  496.   temp_slot_level = p->temp_slot_level;
  497.   current_function_epilogue_delay_list = p->epilogue_delay_list;
  498.  
  499.   restore_tree_status (p);
  500.   restore_storage_status (p);
  501.   restore_expr_status (p);
  502.   restore_emit_status (p);
  503.   restore_stmt_status (p);
  504.   restore_varasm_status (p);
  505.  
  506.   /* Finish doing put_var_into_stack for any of our variables
  507.      which became addressable during the nested function.  */
  508.   {
  509.     struct var_refs_queue *queue = p->fixup_var_refs_queue;
  510.     for (; queue; queue = queue->next)
  511.       fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
  512.   }
  513.  
  514.   free (p);
  515.  
  516.   /* Reset variables that have known state during rtx generation.  */
  517.   rtx_equal_function_value_matters = 1;
  518.   virtuals_instantiated = 0;
  519. }
  520.  
  521. /* Allocate fixed slots in the stack frame of the current function.  */
  522.  
  523. /* Return size needed for stack frame based on slots so far allocated.
  524.    This size counts from zero.  It is not rounded to STACK_BOUNDARY;
  525.    the caller may have to do that.  */
  526.  
  527. int
  528. get_frame_size ()
  529. {
  530. #ifdef FRAME_GROWS_DOWNWARD
  531.   return -frame_offset;
  532. #else
  533.   return frame_offset;
  534. #endif
  535. }
  536.  
  537. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  538.    with machine mode MODE.
  539.    
  540.    ALIGN controls the amount of alignment for the address of the slot:
  541.    0 means according to MODE,
  542.    -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
  543.    positive specifies alignment boundary in bits.
  544.  
  545.    We do not round to stack_boundary here.  */
  546.  
  547. rtx
  548. assign_stack_local (mode, size, align)
  549.      enum machine_mode mode;
  550.      int size;
  551.      int align;
  552. {
  553.   register rtx x, addr;
  554.   int bigend_correction = 0;
  555.   int alignment;
  556.  
  557.   if (align == 0)
  558.     {
  559.       alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
  560.       if (mode == BLKmode)
  561.     alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  562.     }
  563.   else if (align == -1)
  564.     {
  565.       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  566.       size = CEIL_ROUND (size, alignment);
  567.     }
  568.   else
  569.     alignment = align / BITS_PER_UNIT;
  570.  
  571.   /* Round frame offset to that alignment.
  572.      We must be careful here, since FRAME_OFFSET might be negative and
  573.      division with a negative dividend isn't as well defined as we might
  574.      like.  So we instead assume that ALIGNMENT is a power of two and
  575.      use logical operations which are unambiguous.  */
  576. #ifdef FRAME_GROWS_DOWNWARD
  577.   frame_offset = FLOOR_ROUND (frame_offset, alignment);
  578. #else
  579.   frame_offset = CEIL_ROUND (frame_offset, alignment);
  580. #endif
  581.  
  582.   /* On a big-endian machine, if we are allocating more space than we will use,
  583.      use the least significant bytes of those that are allocated.  */
  584. #if BYTES_BIG_ENDIAN
  585.   if (mode != BLKmode)
  586.     bigend_correction = size - GET_MODE_SIZE (mode);
  587. #endif
  588.  
  589. #ifdef FRAME_GROWS_DOWNWARD
  590.   frame_offset -= size;
  591. #endif
  592.  
  593.   /* If we have already instantiated virtual registers, return the actual
  594.      address relative to the frame pointer.  */
  595.   if (virtuals_instantiated)
  596.     addr = plus_constant (frame_pointer_rtx,
  597.               (frame_offset + bigend_correction
  598.                + STARTING_FRAME_OFFSET));
  599.   else
  600.     addr = plus_constant (virtual_stack_vars_rtx,
  601.               frame_offset + bigend_correction);
  602.  
  603. #ifndef FRAME_GROWS_DOWNWARD
  604.   frame_offset += size;
  605. #endif
  606.  
  607.   x = gen_rtx (MEM, mode, addr);
  608.  
  609.   stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
  610.  
  611.   return x;
  612. }
  613.  
  614. /* Assign a stack slot in a containing function.
  615.    First three arguments are same as in preceding function.
  616.    The last argument specifies the function to allocate in.  */
  617.  
  618. rtx
  619. assign_outer_stack_local (mode, size, align, function)
  620.      enum machine_mode mode;
  621.      int size;
  622.      int align;
  623.      struct function *function;
  624. {
  625.   register rtx x, addr;
  626.   int bigend_correction = 0;
  627.   int alignment;
  628.  
  629.   /* Allocate in the memory associated with the function in whose frame
  630.      we are assigning.  */
  631.   push_obstacks (function->function_obstack,
  632.          function->function_maybepermanent_obstack);
  633.  
  634.   if (align == 0)
  635.     {
  636.       alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
  637.       if (mode == BLKmode)
  638.     alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  639.     }
  640.   else if (align == -1)
  641.     {
  642.       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  643.       size = CEIL_ROUND (size, alignment);
  644.     }
  645.   else
  646.     alignment = align / BITS_PER_UNIT;
  647.  
  648.   /* Round frame offset to that alignment.  */
  649. #ifdef FRAME_GROWS_DOWNWARD
  650.   function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
  651. #else
  652.   function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
  653. #endif
  654.  
  655.   /* On a big-endian machine, if we are allocating more space than we will use,
  656.      use the least significant bytes of those that are allocated.  */
  657. #if BYTES_BIG_ENDIAN
  658.   if (mode != BLKmode)
  659.     bigend_correction = size - GET_MODE_SIZE (mode);
  660. #endif
  661.  
  662. #ifdef FRAME_GROWS_DOWNWARD
  663.   function->frame_offset -= size;
  664. #endif
  665.   addr = plus_constant (virtual_stack_vars_rtx,
  666.             function->frame_offset + bigend_correction);
  667. #ifndef FRAME_GROWS_DOWNWARD
  668.   function->frame_offset += size;
  669. #endif
  670.  
  671.   x = gen_rtx (MEM, mode, addr);
  672.  
  673.   function->stack_slot_list
  674.     = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
  675.  
  676.   pop_obstacks ();
  677.  
  678.   return x;
  679. }
  680.  
  681. /* Allocate a temporary stack slot and record it for possible later
  682.    reuse.
  683.  
  684.    MODE is the machine mode to be given to the returned rtx.
  685.  
  686.    SIZE is the size in units of the space required.  We do no rounding here
  687.    since assign_stack_local will do any required rounding.
  688.  
  689.    KEEP is non-zero if this slot is to be retained after a call to
  690.    free_temp_slots.  Automatic variables for a block are allocated with this
  691.    flag.  */
  692.  
  693. rtx
  694. assign_stack_temp (mode, size, keep)
  695.      enum machine_mode mode;
  696.      int size;
  697.      int keep;
  698. {
  699.   struct temp_slot *p, *best_p = 0;
  700.  
  701.   /* First try to find an available, already-allocated temporary that is the
  702.      exact size we require.  */
  703.   for (p = temp_slots; p; p = p->next)
  704.     if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
  705.       break;
  706.  
  707.   /* If we didn't find, one, try one that is larger than what we want.  We
  708.      find the smallest such.  */
  709.   if (p == 0)
  710.     for (p = temp_slots; p; p = p->next)
  711.       if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
  712.       && (best_p == 0 || best_p->size > p->size))
  713.     best_p = p;
  714.  
  715.   /* Make our best, if any, the one to use.  */
  716.   if (best_p)
  717.     p = best_p;
  718.  
  719.   /* If we still didn't find one, make a new temporary.  */
  720.   if (p == 0)
  721.     {
  722.       p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
  723.       p->size = size;
  724.       /* If the temp slot mode doesn't indicate the alignment,
  725.      use the largest possible, so no one will be disappointed.  */
  726.       p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0); 
  727.       p->next = temp_slots;
  728.       temp_slots = p;
  729.     }
  730.  
  731.   p->in_use = 1;
  732.   p->level = temp_slot_level;
  733.   p->keep = keep;
  734.   return p->slot;
  735. }
  736.  
  737. /* If X could be a reference to a temporary slot, mark that slot as belonging
  738.    to the to one level higher.  If X matched one of our slots, just mark that
  739.    one.  Otherwise, we can't easily predict which it is, so upgrade all of
  740.    them.  Kept slots need not be touched.
  741.  
  742.    This is called when an ({...}) construct occurs and a statement
  743.    returns a value in memory.  */
  744.  
  745. void
  746. preserve_temp_slots (x)
  747.      rtx x;
  748. {
  749.   struct temp_slot *p;
  750.  
  751.   /* If X is not in memory or is at a constant address, it cannot be in
  752.      a temporary slot.  */
  753.   if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
  754.     return;
  755.  
  756.   /* First see if we can find a match.  */
  757.   for (p = temp_slots; p; p = p->next)
  758.     if (p->in_use && x == p->slot)
  759.       {
  760.     p->level--;
  761.     return;
  762.       }
  763.  
  764.   /* Otherwise, preserve all non-kept slots at this level.  */
  765.   for (p = temp_slots; p; p = p->next)
  766.     if (p->in_use && p->level == temp_slot_level && ! p->keep)
  767.       p->level--;
  768. }
  769.  
  770. /* Free all temporaries used so far.  This is normally called at the end
  771.    of generating code for a statement.  */
  772.  
  773. void
  774. free_temp_slots ()
  775. {
  776.   struct temp_slot *p;
  777.  
  778.   for (p = temp_slots; p; p = p->next)
  779.     if (p->in_use && p->level == temp_slot_level && ! p->keep)
  780.       p->in_use = 0;
  781. }
  782.  
  783. /* Push deeper into the nesting level for stack temporaries.  */
  784.  
  785. void
  786. push_temp_slots ()
  787. {
  788.   /* For GNU C++, we must allow a sequence to be emitted anywhere in
  789.      the level where the sequence was started.  By not changing levels
  790.      when the compiler is inside a sequence, the temporaries for the
  791.      sequence and the temporaries will not unwittingly conflict with
  792.      the temporaries for other sequences and/or code at that level.  */
  793.   if (in_sequence_p ())
  794.     return;
  795.  
  796.   temp_slot_level++;
  797. }
  798.  
  799. /* Pop a temporary nesting level.  All slots in use in the current level
  800.    are freed.  */
  801.  
  802. void
  803. pop_temp_slots ()
  804. {
  805.   struct temp_slot *p;
  806.  
  807.   /* See comment in push_temp_slots about why we don't change levels
  808.      in sequences.  */
  809.   if (in_sequence_p ())
  810.     return;
  811.  
  812.   for (p = temp_slots; p; p = p->next)
  813.     if (p->in_use && p->level == temp_slot_level)
  814.       p->in_use = 0;
  815.  
  816.   temp_slot_level--;
  817. }
  818.  
  819. /* Retroactively move an auto variable from a register to a stack slot.
  820.    This is done when an address-reference to the variable is seen.  */
  821.  
  822. void
  823. put_var_into_stack (decl)
  824.      tree decl;
  825. {
  826.   register rtx reg;
  827.   register rtx new = 0;
  828.   enum machine_mode promoted_mode, decl_mode;
  829.   struct function *function = 0;
  830.   tree context = decl_function_context (decl);
  831.  
  832.   /* Get the current rtl used for this object and it's original mode.  */
  833.   reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
  834.  
  835.   /* No need to do anything if decl has no rtx yet
  836.      since in that case caller is setting TREE_ADDRESSABLE
  837.      and a stack slot will be assigned when the rtl is made.  */
  838.   if (reg == 0)
  839.     return;
  840.  
  841.   /* Get the declared mode for this object.  */
  842.   decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
  843.            : DECL_MODE (decl));
  844.   /* Get the mode it's actually stored in.  */
  845.   promoted_mode = GET_MODE (reg);
  846.  
  847.   /* If this variable comes from an outer function,
  848.      find that function's saved context.  */
  849.   if (context != current_function_decl)
  850.     for (function = outer_function_chain; function; function = function->next)
  851.       if (function->decl == context)
  852.     break;
  853.  
  854.   /* If this is a variable-size object with a pseudo to address it,
  855.      put that pseudo into the stack, if the var is nonlocal.  */
  856.   if (DECL_NONLOCAL (decl)
  857.       && GET_CODE (reg) == MEM
  858.       && GET_CODE (XEXP (reg, 0)) == REG
  859.       && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
  860.     {
  861.       reg = XEXP (reg, 0);
  862.       decl_mode = promoted_mode = GET_MODE (reg);
  863.     }
  864.   if (GET_CODE (reg) != REG)
  865.     return;
  866.  
  867.   if (function)
  868.     {
  869.       if (REGNO (reg) < function->max_parm_reg)
  870.     new = function->parm_reg_stack_loc[REGNO (reg)];
  871.       if (new == 0)
  872.     new = assign_outer_stack_local (GET_MODE (reg),
  873.                     GET_MODE_SIZE (decl_mode),
  874.                     0, function);
  875.     }
  876.   else
  877.     {
  878.       if (REGNO (reg) < max_parm_reg)
  879.     new = parm_reg_stack_loc[REGNO (reg)];
  880.       if (new == 0)
  881.     new = assign_stack_local (GET_MODE (reg),
  882.                   GET_MODE_SIZE (decl_mode), 0);
  883.     }
  884.  
  885.   XEXP (reg, 0) = XEXP (new, 0);
  886.   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
  887.   REG_USERVAR_P (reg) = 0;
  888.   PUT_CODE (reg, MEM);
  889.   PUT_MODE (reg, decl_mode);
  890.  
  891.   /* If this is a memory ref that contains aggregate components,
  892.      mark it as such for cse and loop optimize.  */
  893.   MEM_IN_STRUCT_P (reg)
  894.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  895.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  896.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  897.  
  898.   /* Now make sure that all refs to the variable, previously made
  899.      when it was a register, are fixed up to be valid again.  */
  900.   if (function)
  901.     {
  902.       struct var_refs_queue *temp;
  903.  
  904.       /* Variable is inherited; fix it up when we get back to its function.  */
  905.       push_obstacks (function->function_obstack,
  906.              function->function_maybepermanent_obstack);
  907.       temp
  908.     = (struct var_refs_queue *) oballoc (sizeof (struct var_refs_queue));
  909.       temp->modified = reg;
  910.       temp->promoted_mode = promoted_mode;
  911.       temp->unsignedp = TREE_UNSIGNED (TREE_TYPE (decl));
  912.       temp->next = function->fixup_var_refs_queue;
  913.       function->fixup_var_refs_queue = temp;
  914.       pop_obstacks ();
  915.     }
  916.   else
  917.     /* Variable is local; fix it up now.  */
  918.     fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (TREE_TYPE (decl)));
  919. }
  920.  
  921. static void
  922. fixup_var_refs (var, promoted_mode, unsignedp)
  923.      rtx var;
  924.      enum machine_mode promoted_mode;
  925.      int unsignedp;
  926. {
  927.   tree pending;
  928.   rtx first_insn = get_insns ();
  929.   struct sequence_stack *stack = sequence_stack;
  930.   tree rtl_exps = rtl_expr_chain;
  931.  
  932.   /* Must scan all insns for stack-refs that exceed the limit.  */
  933.   fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
  934.  
  935.   /* Scan all pending sequences too.  */
  936.   for (; stack; stack = stack->next)
  937.     {
  938.       push_to_sequence (stack->first);
  939.       fixup_var_refs_insns (var, promoted_mode, unsignedp,
  940.                 stack->first, stack->next != 0);
  941.       /* Update remembered end of sequence
  942.      in case we added an insn at the end.  */
  943.       stack->last = get_last_insn ();
  944.       end_sequence ();
  945.     }
  946.  
  947.   /* Scan all waiting RTL_EXPRs too.  */
  948.   for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
  949.     {
  950.       rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
  951.       if (seq != const0_rtx && seq != 0)
  952.     {
  953.       push_to_sequence (seq);
  954.       fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
  955.       end_sequence ();
  956.     }
  957.     }
  958. }
  959.  
  960. /* This structure is used by the following two functions to record MEMs or
  961.    pseudos used to replace VAR, any SUBREGs of VAR, and any MEMs containing
  962.    VAR as an address.  We need to maintain this list in case two operands of
  963.    an insn were required to match; in that case we must ensure we use the
  964.    same replacement.  */
  965.  
  966. struct fixup_replacement
  967. {
  968.   rtx old;
  969.   rtx new;
  970.   struct fixup_replacement *next;
  971. };
  972.    
  973. /* REPLACEMENTS is a pointer to a list of the above structures and X is
  974.    some part of an insn.  Return a struct fixup_replacement whose OLD
  975.    value is equal to X.  Allocate a new structure if no such entry exists. */
  976.  
  977. static struct fixup_replacement *
  978. find_fixup_replacement (replacements, x)
  979.      struct fixup_replacement **replacements;
  980.      rtx x;
  981. {
  982.   struct fixup_replacement *p;
  983.  
  984.   /* See if we have already replaced this.  */
  985.   for (p = *replacements; p && p->old != x; p = p->next)
  986.     ;
  987.  
  988.   if (p == 0)
  989.     {
  990.       p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
  991.       p->old = x;
  992.       p->new = 0;
  993.       p->next = *replacements;
  994.       *replacements = p;
  995.     }
  996.  
  997.   return p;
  998. }
  999.  
  1000. /* Scan the insn-chain starting with INSN for refs to VAR
  1001.    and fix them up.  TOPLEVEL is nonzero if this chain is the
  1002.    main chain of insns for the current function.  */
  1003.  
  1004. static void
  1005. fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
  1006.      rtx var;
  1007.      enum machine_mode promoted_mode;
  1008.      int unsignedp;
  1009.      rtx insn;
  1010.      int toplevel;
  1011. {
  1012.   while (insn)
  1013.     {
  1014.       rtx next = NEXT_INSN (insn);
  1015.       rtx note;
  1016.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1017.       || GET_CODE (insn) == JUMP_INSN)
  1018.     {
  1019.       /* The insn to load VAR from a home in the arglist
  1020.          is now a no-op.  When we see it, just delete it.  */
  1021.       if (toplevel
  1022.           && GET_CODE (PATTERN (insn)) == SET
  1023.           && SET_DEST (PATTERN (insn)) == var
  1024.           && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  1025.         {
  1026.           /* In unoptimized compilation, we shouldn't call delete_insn
  1027.          except in jump.c doing warnings.  */
  1028.           PUT_CODE (insn, NOTE);
  1029.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1030.           NOTE_SOURCE_FILE (insn) = 0;
  1031.           if (insn == last_parm_insn)
  1032.         last_parm_insn = PREV_INSN (next);
  1033.         }
  1034.       else
  1035.         {
  1036.           /* See if we have to do anything to INSN now that VAR is in
  1037.          memory.  If it needs to be loaded into a pseudo, use a single
  1038.          pseudo for the entire insn in case there is a MATCH_DUP
  1039.          between two operands.  We pass a pointer to the head of
  1040.          a list of struct fixup_replacements.  If fixup_var_refs_1
  1041.          needs to allocate pseudos or replacement MEMs (for SUBREGs),
  1042.          it will record them in this list.
  1043.          
  1044.          If it allocated a pseudo for any replacement, we copy into
  1045.          it here.  */
  1046.  
  1047.           struct fixup_replacement *replacements = 0;
  1048.  
  1049.           fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
  1050.                 &replacements);
  1051.  
  1052.           while (replacements)
  1053.         {
  1054.           if (GET_CODE (replacements->new) == REG)
  1055.             {
  1056.               rtx insert_before;
  1057.               rtx seq;
  1058.  
  1059.               /* OLD might be a (subreg (mem)).  */
  1060.               if (GET_CODE (replacements->old) == SUBREG)
  1061.             replacements->old
  1062.               = fixup_memory_subreg (replacements->old, insn, 0);
  1063.               else
  1064.             replacements->old
  1065.               = fixup_stack_1 (replacements->old, insn);
  1066.  
  1067.               /* We can not separate USE insns from the CALL_INSN
  1068.              that they belong to.  If this is a CALL_INSN, insert
  1069.              the move insn before the USE insns preceding it
  1070.              instead of immediately before the insn.  */
  1071.               if (GET_CODE (insn) == CALL_INSN)
  1072.             {
  1073.               insert_before = insn;
  1074.               while (GET_CODE (PREV_INSN (insert_before)) == INSN
  1075.                  && GET_CODE (PATTERN (PREV_INSN (insert_before))) == USE)
  1076.                 insert_before = PREV_INSN (insert_before);
  1077.             }
  1078.               else
  1079.             insert_before = insn;
  1080.  
  1081.               /* If we are changing the mode, do a conversion.
  1082.              This might be wasteful, but combine.c will
  1083.              eliminate much of the waste.  */
  1084.  
  1085.               if (GET_MODE (replacements->new)
  1086.               != GET_MODE (replacements->old))
  1087.             {
  1088.               start_sequence ();
  1089.               convert_move (replacements->new,
  1090.                     replacements->old, unsignedp);
  1091.               seq = gen_sequence ();
  1092.               end_sequence ();
  1093.             }
  1094.               else
  1095.             seq = gen_move_insn (replacements->new,
  1096.                          replacements->old);
  1097.  
  1098.               emit_insn_before (seq, insert_before);
  1099.             }
  1100.  
  1101.           replacements = replacements->next;
  1102.         }
  1103.         }
  1104.  
  1105.       /* Also fix up any invalid exprs in the REG_NOTES of this insn.
  1106.          But don't touch other insns referred to by reg-notes;
  1107.          we will get them elsewhere.  */
  1108.       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1109.         if (GET_CODE (note) != INSN_LIST)
  1110.           XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn);
  1111.     }
  1112.       insn = next;
  1113.     }
  1114. }
  1115.  
  1116. /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
  1117.    See if the rtx expression at *LOC in INSN needs to be changed.  
  1118.  
  1119.    REPLACEMENTS is a pointer to a list head that starts out zero, but may
  1120.    contain a list of original rtx's and replacements. If we find that we need
  1121.    to modify this insn by replacing a memory reference with a pseudo or by
  1122.    making a new MEM to implement a SUBREG, we consult that list to see if
  1123.    we have already chosen a replacement. If none has already been allocated,
  1124.    we allocate it and update the list.  fixup_var_refs_insns will copy VAR
  1125.    or the SUBREG, as appropriate, to the pseudo.  */
  1126.  
  1127. static void
  1128. fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
  1129.      register rtx var;
  1130.      enum machine_mode promoted_mode;
  1131.      register rtx *loc;
  1132.      rtx insn;
  1133.      struct fixup_replacement **replacements;
  1134. {
  1135.   register int i;
  1136.   register rtx x = *loc;
  1137.   RTX_CODE code = GET_CODE (x);
  1138.   register char *fmt;
  1139.   register rtx tem, tem1;
  1140.   struct fixup_replacement *replacement;
  1141.  
  1142.   switch (code)
  1143.     {
  1144.     case MEM:
  1145.       if (var == x)
  1146.     {
  1147.       /* If we already have a replacement, use it.  Otherwise, 
  1148.          try to fix up this address in case it is invalid.  */
  1149.  
  1150.       replacement = find_fixup_replacement (replacements, var);
  1151.       if (replacement->new)
  1152.         {
  1153.           *loc = replacement->new;
  1154.           return;
  1155.         }
  1156.  
  1157.       *loc = replacement->new = x = fixup_stack_1 (x, insn);
  1158.  
  1159.       /* Unless we are forcing memory to register or we changed the mode,
  1160.          we can leave things the way they are if the insn is valid.  */
  1161.          
  1162.       INSN_CODE (insn) = -1;
  1163.       if (! flag_force_mem && GET_MODE (x) == promoted_mode
  1164.           && recog_memoized (insn) >= 0)
  1165.         return;
  1166.  
  1167.       *loc = replacement->new = gen_reg_rtx (promoted_mode);
  1168.       return;
  1169.     }
  1170.  
  1171.       /* If X contains VAR, we need to unshare it here so that we update
  1172.      each occurrence separately.  But all identical MEMs in one insn
  1173.      must be replaced with the same rtx because of the possibility of
  1174.      MATCH_DUPs.  */
  1175.  
  1176.       if (reg_mentioned_p (var, x))
  1177.     {
  1178.       replacement = find_fixup_replacement (replacements, x);
  1179.       if (replacement->new == 0)
  1180.         replacement->new = copy_most_rtx (x, var);
  1181.  
  1182.       *loc = x = replacement->new;
  1183.     }
  1184.       break;
  1185.  
  1186.     case REG:
  1187.     case CC0:
  1188.     case PC:
  1189.     case CONST_INT:
  1190.     case CONST:
  1191.     case SYMBOL_REF:
  1192.     case LABEL_REF:
  1193.     case CONST_DOUBLE:
  1194.       return;
  1195.  
  1196.     case SIGN_EXTRACT:
  1197.     case ZERO_EXTRACT:
  1198.       /* Note that in some cases those types of expressions are altered
  1199.      by optimize_bit_field, and do not survive to get here.  */
  1200.       if (XEXP (x, 0) == var
  1201.       || (GET_CODE (XEXP (x, 0)) == SUBREG
  1202.           && SUBREG_REG (XEXP (x, 0)) == var))
  1203.     {
  1204.       /* Get TEM as a valid MEM in the mode presently in the insn.
  1205.  
  1206.          We don't worry about the possibility of MATCH_DUP here; it
  1207.          is highly unlikely and would be tricky to handle.  */
  1208.  
  1209.       tem = XEXP (x, 0);
  1210.       if (GET_CODE (tem) == SUBREG)
  1211.         tem = fixup_memory_subreg (tem, insn, 1);
  1212.       tem = fixup_stack_1 (tem, insn);
  1213.  
  1214.       /* Unless we want to load from memory, get TEM into the proper mode
  1215.          for an extract from memory.  This can only be done if the
  1216.          extract is at a constant position and length.  */
  1217.  
  1218.       if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
  1219.           && GET_CODE (XEXP (x, 2)) == CONST_INT
  1220.           && ! mode_dependent_address_p (XEXP (tem, 0))
  1221.           && ! MEM_VOLATILE_P (tem))
  1222.         {
  1223.           enum machine_mode wanted_mode = VOIDmode;
  1224.           enum machine_mode is_mode = GET_MODE (tem);
  1225.           int width = INTVAL (XEXP (x, 1));
  1226.           int pos = INTVAL (XEXP (x, 2));
  1227.  
  1228. #ifdef HAVE_extzv
  1229.           if (GET_CODE (x) == ZERO_EXTRACT)
  1230.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
  1231. #endif
  1232. #ifdef HAVE_extv
  1233.           if (GET_CODE (x) == SIGN_EXTRACT)
  1234.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
  1235. #endif
  1236.           /* If we have a narrower mode, we can do something.  */
  1237.           if (wanted_mode != VOIDmode
  1238.           && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  1239.         {
  1240.           int offset = pos / BITS_PER_UNIT;
  1241.           rtx old_pos = XEXP (x, 2);
  1242.           rtx newmem;
  1243.  
  1244.           /* If the bytes and bits are counted differently, we
  1245.              must adjust the offset.  */
  1246. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  1247.           offset = (GET_MODE_SIZE (is_mode)
  1248.                 - GET_MODE_SIZE (wanted_mode) - offset);
  1249. #endif
  1250.  
  1251.           pos %= GET_MODE_BITSIZE (wanted_mode);
  1252.  
  1253.           newmem = gen_rtx (MEM, wanted_mode,
  1254.                     plus_constant (XEXP (tem, 0), offset));
  1255.           RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
  1256.           MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
  1257.           MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
  1258.  
  1259.           /* Make the change and see if the insn remains valid.  */
  1260.           INSN_CODE (insn) = -1;
  1261.           XEXP (x, 0) = newmem;
  1262.           XEXP (x, 2) = GEN_INT (pos);
  1263.  
  1264.           if (recog_memoized (insn) >= 0)
  1265.             return;
  1266.  
  1267.           /* Otherwise, restore old position.  XEXP (x, 0) will be
  1268.              restored later.  */
  1269.           XEXP (x, 2) = old_pos;
  1270.         }
  1271.         }
  1272.  
  1273.       /* If we get here, the bitfield extract insn can't accept a memory
  1274.          reference.  Copy the input into a register.  */
  1275.  
  1276.       tem1 = gen_reg_rtx (GET_MODE (tem));
  1277.       emit_insn_before (gen_move_insn (tem1, tem), insn);
  1278.       XEXP (x, 0) = tem1;
  1279.       return;
  1280.     }
  1281.       break;
  1282.           
  1283.     case SUBREG:
  1284.       if (SUBREG_REG (x) == var)
  1285.     {
  1286.       /* If this is a special SUBREG made because VAR was promoted
  1287.          from a wider mode, replace it with VAR and call ourself
  1288.          recursively, this time saying that the object previously
  1289.          had its current mode (by virtue of the SUBREG).  */
  1290.  
  1291.       if (SUBREG_PROMOTED_VAR_P (x))
  1292.         {
  1293.           *loc = var;
  1294.           fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
  1295.           return;
  1296.         }
  1297.  
  1298.       /* If this SUBREG makes VAR wider, it has become a paradoxical
  1299.          SUBREG with VAR in memory, but these aren't allowed at this 
  1300.          stage of the compilation.  So load VAR into a pseudo and take
  1301.          a SUBREG of that pseudo.  */
  1302.       if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
  1303.         {
  1304.           replacement = find_fixup_replacement (replacements, var);
  1305.           if (replacement->new == 0)
  1306.         replacement->new = gen_reg_rtx (GET_MODE (var));
  1307.           SUBREG_REG (x) = replacement->new;
  1308.           return;
  1309.         }
  1310.  
  1311.       /* See if we have already found a replacement for this SUBREG.
  1312.          If so, use it.  Otherwise, make a MEM and see if the insn
  1313.          is recognized.  If not, or if we should force MEM into a register,
  1314.          make a pseudo for this SUBREG.  */
  1315.       replacement = find_fixup_replacement (replacements, x);
  1316.       if (replacement->new)
  1317.         {
  1318.           *loc = replacement->new;
  1319.           return;
  1320.         }
  1321.       
  1322.       replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
  1323.  
  1324.       if (! flag_force_mem && recog_memoized (insn) >= 0)
  1325.         return;
  1326.  
  1327.       *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
  1328.       return;
  1329.     }
  1330.       break;
  1331.  
  1332.     case SET:
  1333.       /* First do special simplification of bit-field references.  */
  1334.       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  1335.       || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  1336.     optimize_bit_field (x, insn, 0);
  1337.       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  1338.       || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  1339.     optimize_bit_field (x, insn, NULL_PTR);
  1340.  
  1341.       /* If SET_DEST is now a paradoxical SUBREG, put the result of this
  1342.      insn into a pseudo and store the low part of the pseudo into VAR. */
  1343.       if (GET_CODE (SET_DEST (x)) == SUBREG
  1344.       && SUBREG_REG (SET_DEST (x)) == var
  1345.       && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
  1346.           > GET_MODE_SIZE (GET_MODE (var))))
  1347.     {
  1348.       SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
  1349.       emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
  1350.                                 tem)),
  1351.                insn);
  1352.       break;
  1353.     }
  1354.       
  1355.       {
  1356.     rtx dest = SET_DEST (x);
  1357.     rtx src = SET_SRC (x);
  1358.     rtx outerdest = dest;
  1359.  
  1360.     while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  1361.            || GET_CODE (dest) == SIGN_EXTRACT
  1362.            || GET_CODE (dest) == ZERO_EXTRACT)
  1363.       dest = XEXP (dest, 0);
  1364.  
  1365.     if (GET_CODE (src) == SUBREG)
  1366.       src = XEXP (src, 0);
  1367.  
  1368.     /* If VAR does not appear at the top level of the SET
  1369.        just scan the lower levels of the tree.  */
  1370.  
  1371.         if (src != var && dest != var)
  1372.       break;
  1373.  
  1374.     /* We will need to rerecognize this insn.  */
  1375.     INSN_CODE (insn) = -1;
  1376.  
  1377. #ifdef HAVE_insv
  1378.     if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
  1379.       {
  1380.         /* Since this case will return, ensure we fixup all the
  1381.            operands here.  */
  1382.         fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
  1383.                   insn, replacements);
  1384.         fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
  1385.                   insn, replacements);
  1386.         fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
  1387.                   insn, replacements);
  1388.  
  1389.         tem = XEXP (outerdest, 0);
  1390.  
  1391.         /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  1392.            that may appear inside a ZERO_EXTRACT.
  1393.            This was legitimate when the MEM was a REG.  */
  1394.         if (GET_CODE (tem) == SUBREG
  1395.         && SUBREG_REG (tem) == var)
  1396.           tem = fixup_memory_subreg (tem, insn, 1);
  1397.         else
  1398.           tem = fixup_stack_1 (tem, insn);
  1399.  
  1400.         if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
  1401.         && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
  1402.         && ! mode_dependent_address_p (XEXP (tem, 0))
  1403.         && ! MEM_VOLATILE_P (tem))
  1404.           {
  1405.         enum machine_mode wanted_mode
  1406.           = insn_operand_mode[(int) CODE_FOR_insv][0];
  1407.         enum machine_mode is_mode = GET_MODE (tem);
  1408.         int width = INTVAL (XEXP (outerdest, 1));
  1409.         int pos = INTVAL (XEXP (outerdest, 2));
  1410.  
  1411.         /* If we have a narrower mode, we can do something.  */
  1412.         if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  1413.           {
  1414.             int offset = pos / BITS_PER_UNIT;
  1415.             rtx old_pos = XEXP (outerdest, 2);
  1416.             rtx newmem;
  1417.  
  1418. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  1419.             offset = (GET_MODE_SIZE (is_mode)
  1420.                   - GET_MODE_SIZE (wanted_mode) - offset);
  1421. #endif
  1422.  
  1423.             pos %= GET_MODE_BITSIZE (wanted_mode);
  1424.  
  1425.             newmem = gen_rtx (MEM, wanted_mode,
  1426.                       plus_constant (XEXP (tem, 0), offset));
  1427.             RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
  1428.             MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
  1429.             MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
  1430.  
  1431.             /* Make the change and see if the insn remains valid.  */
  1432.             INSN_CODE (insn) = -1;
  1433.             XEXP (outerdest, 0) = newmem;
  1434.             XEXP (outerdest, 2) = GEN_INT (pos);
  1435.             
  1436.             if (recog_memoized (insn) >= 0)
  1437.               return;
  1438.             
  1439.             /* Otherwise, restore old position.  XEXP (x, 0) will be
  1440.                restored later.  */
  1441.             XEXP (outerdest, 2) = old_pos;
  1442.           }
  1443.           }
  1444.  
  1445.         /* If we get here, the bit-field store doesn't allow memory
  1446.            or isn't located at a constant position.  Load the value into
  1447.            a register, do the store, and put it back into memory.  */
  1448.  
  1449.         tem1 = gen_reg_rtx (GET_MODE (tem));
  1450.         emit_insn_before (gen_move_insn (tem1, tem), insn);
  1451.         emit_insn_after (gen_move_insn (tem, tem1), insn);
  1452.         XEXP (outerdest, 0) = tem1;
  1453.         return;
  1454.       }
  1455. #endif
  1456.  
  1457.     /* STRICT_LOW_PART is a no-op on memory references
  1458.        and it can cause combinations to be unrecognizable,
  1459.        so eliminate it.  */
  1460.  
  1461.     if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  1462.       SET_DEST (x) = XEXP (SET_DEST (x), 0);
  1463.  
  1464.     /* A valid insn to copy VAR into or out of a register
  1465.        must be left alone, to avoid an infinite loop here.
  1466.        If the reference to VAR is by a subreg, fix that up,
  1467.        since SUBREG is not valid for a memref.
  1468.        Also fix up the address of the stack slot.  */
  1469.  
  1470.     if ((SET_SRC (x) == var
  1471.          || (GET_CODE (SET_SRC (x)) == SUBREG
  1472.          && SUBREG_REG (SET_SRC (x)) == var))
  1473.         && (GET_CODE (SET_DEST (x)) == REG
  1474.         || (GET_CODE (SET_DEST (x)) == SUBREG
  1475.             && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  1476.         && recog_memoized (insn) >= 0)
  1477.       {
  1478.         replacement = find_fixup_replacement (replacements, SET_SRC (x));
  1479.         if (replacement->new)
  1480.           {
  1481.           SET_SRC (x) = replacement->new;
  1482.           return;
  1483.         }
  1484.         else if (GET_CODE (SET_SRC (x)) == SUBREG)
  1485.           SET_SRC (x) = replacement->new
  1486.         = fixup_memory_subreg (SET_SRC (x), insn, 0);
  1487.         else
  1488.           SET_SRC (x) = replacement->new
  1489.         = fixup_stack_1 (SET_SRC (x), insn);
  1490.         return;
  1491.       }
  1492.  
  1493.     if ((SET_DEST (x) == var
  1494.          || (GET_CODE (SET_DEST (x)) == SUBREG
  1495.          && SUBREG_REG (SET_DEST (x)) == var))
  1496.         && (GET_CODE (SET_SRC (x)) == REG
  1497.         || (GET_CODE (SET_SRC (x)) == SUBREG
  1498.             && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
  1499.         && recog_memoized (insn) >= 0)
  1500.       {
  1501.         if (GET_CODE (SET_DEST (x)) == SUBREG)
  1502.           SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
  1503.         else
  1504.           SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
  1505.         return;
  1506.       }
  1507.  
  1508.     /* Otherwise, storing into VAR must be handled specially
  1509.        by storing into a temporary and copying that into VAR
  1510.        with a new insn after this one.  Note that this case
  1511.        will be used when storing into a promoted scalar since
  1512.        the insn will now have different modes on the input
  1513.        and output and hence will be invalid (except for the case
  1514.        of setting it to a constant, which does not need any
  1515.        change if it is valid).  We generate extra code in that case,
  1516.        but combine.c will eliminate it.  */
  1517.  
  1518.     if (dest == var)
  1519.       {
  1520.         rtx temp;
  1521.         rtx fixeddest = SET_DEST (x);
  1522.  
  1523.         /* STRICT_LOW_PART can be discarded, around a MEM.  */
  1524.         if (GET_CODE (fixeddest) == STRICT_LOW_PART)
  1525.           fixeddest = XEXP (fixeddest, 0);
  1526.         /* Convert (SUBREG (MEM)) to a MEM in a changed mode.  */
  1527.         if (GET_CODE (fixeddest) == SUBREG)
  1528.           fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
  1529.         else
  1530.           fixeddest = fixup_stack_1 (fixeddest, insn);
  1531.  
  1532.         temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
  1533.                 ? GET_MODE (fixeddest)
  1534.                 : GET_MODE (SET_SRC (x)));
  1535.  
  1536.         emit_insn_after (gen_move_insn (fixeddest,
  1537.                         gen_lowpart (GET_MODE (fixeddest),
  1538.                              temp)),
  1539.                  insn);
  1540.  
  1541.         SET_DEST (x) = temp;
  1542.       }
  1543.       }
  1544.     }
  1545.  
  1546.   /* Nothing special about this RTX; fix its operands.  */
  1547.  
  1548.   fmt = GET_RTX_FORMAT (code);
  1549.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1550.     {
  1551.       if (fmt[i] == 'e')
  1552.     fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
  1553.       if (fmt[i] == 'E')
  1554.     {
  1555.       register int j;
  1556.       for (j = 0; j < XVECLEN (x, i); j++)
  1557.         fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
  1558.                   insn, replacements);
  1559.     }
  1560.     }
  1561. }
  1562.  
  1563. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  1564.    return an rtx (MEM:m1 newaddr) which is equivalent.
  1565.    If any insns must be emitted to compute NEWADDR, put them before INSN.
  1566.  
  1567.    UNCRITICAL nonzero means accept paradoxical subregs.
  1568.    This is used for subregs found inside of ZERO_EXTRACTs.  */
  1569.  
  1570. static rtx
  1571. fixup_memory_subreg (x, insn, uncritical)
  1572.      rtx x;
  1573.      rtx insn;
  1574.      int uncritical;
  1575. {
  1576.   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1577.   rtx addr = XEXP (SUBREG_REG (x), 0);
  1578.   enum machine_mode mode = GET_MODE (x);
  1579.   rtx saved, result;
  1580.  
  1581.   /* Paradoxical SUBREGs are usually invalid during RTL generation.  */
  1582.   if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  1583.       && ! uncritical)
  1584.     abort ();
  1585.  
  1586. #if BYTES_BIG_ENDIAN
  1587.   offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  1588.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  1589. #endif
  1590.   addr = plus_constant (addr, offset);
  1591.   if (!flag_force_addr && memory_address_p (mode, addr))
  1592.     /* Shortcut if no insns need be emitted.  */
  1593.     return change_address (SUBREG_REG (x), mode, addr);
  1594.   start_sequence ();
  1595.   result = change_address (SUBREG_REG (x), mode, addr);
  1596.   emit_insn_before (gen_sequence (), insn);
  1597.   end_sequence ();
  1598.   return result;
  1599. }
  1600.  
  1601. /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
  1602.    Replace subexpressions of X in place.
  1603.    If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
  1604.    Otherwise return X, with its contents possibly altered.
  1605.  
  1606.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  1607.  
  1608. static rtx
  1609. walk_fixup_memory_subreg (x, insn)
  1610.      register rtx x;
  1611.      rtx insn;
  1612. {
  1613.   register enum rtx_code code;
  1614.   register char *fmt;
  1615.   register int i;
  1616.  
  1617.   if (x == 0)
  1618.     return 0;
  1619.  
  1620.   code = GET_CODE (x);
  1621.  
  1622.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  1623.     return fixup_memory_subreg (x, insn, 0);
  1624.  
  1625.   /* Nothing special about this RTX; fix its operands.  */
  1626.  
  1627.   fmt = GET_RTX_FORMAT (code);
  1628.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1629.     {
  1630.       if (fmt[i] == 'e')
  1631.     XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn);
  1632.       if (fmt[i] == 'E')
  1633.     {
  1634.       register int j;
  1635.       for (j = 0; j < XVECLEN (x, i); j++)
  1636.         XVECEXP (x, i, j)
  1637.           = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn);
  1638.     }
  1639.     }
  1640.   return x;
  1641. }
  1642.  
  1643. #if 0
  1644. /* Fix up any references to stack slots that are invalid memory addresses
  1645.    because they exceed the maximum range of a displacement.  */
  1646.  
  1647. void
  1648. fixup_stack_slots ()
  1649. {
  1650.   register rtx insn;
  1651.  
  1652.   /* Did we generate a stack slot that is out of range
  1653.      or otherwise has an invalid address?  */
  1654.   if (invalid_stack_slot)
  1655.     {
  1656.       /* Yes.  Must scan all insns for stack-refs that exceed the limit.  */
  1657.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  1658.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1659.         || GET_CODE (insn) == JUMP_INSN)
  1660.       fixup_stack_1 (PATTERN (insn), insn);
  1661.     }
  1662. }
  1663. #endif
  1664.  
  1665. /* For each memory ref within X, if it refers to a stack slot
  1666.    with an out of range displacement, put the address in a temp register
  1667.    (emitting new insns before INSN to load these registers)
  1668.    and alter the memory ref to use that register.
  1669.    Replace each such MEM rtx with a copy, to avoid clobberage.  */
  1670.  
  1671. static rtx
  1672. fixup_stack_1 (x, insn)
  1673.      rtx x;
  1674.      rtx insn;
  1675. {
  1676.   register int i;
  1677.   register RTX_CODE code = GET_CODE (x);
  1678.   register char *fmt;
  1679.  
  1680.   if (code == MEM)
  1681.     {
  1682.       register rtx ad = XEXP (x, 0);
  1683.       /* If we have address of a stack slot but it's not valid
  1684.      (displacement is too large), compute the sum in a register.  */
  1685.       if (GET_CODE (ad) == PLUS
  1686.       && GET_CODE (XEXP (ad, 0)) == REG
  1687.       && REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
  1688.       && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER
  1689.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  1690.     {
  1691.       rtx temp, seq;
  1692.       if (memory_address_p (GET_MODE (x), ad))
  1693.         return x;
  1694.  
  1695.       start_sequence ();
  1696.       temp = copy_to_reg (ad);
  1697.       seq = gen_sequence ();
  1698.       end_sequence ();
  1699.       emit_insn_before (seq, insn);
  1700.       return change_address (x, VOIDmode, temp);
  1701.     }
  1702.       return x;
  1703.     }
  1704.  
  1705.   fmt = GET_RTX_FORMAT (code);
  1706.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1707.     {
  1708.       if (fmt[i] == 'e')
  1709.     XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  1710.       if (fmt[i] == 'E')
  1711.     {
  1712.       register int j;
  1713.       for (j = 0; j < XVECLEN (x, i); j++)
  1714.         XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  1715.     }
  1716.     }
  1717.   return x;
  1718. }
  1719.  
  1720. /* Optimization: a bit-field instruction whose field
  1721.    happens to be a byte or halfword in memory
  1722.    can be changed to a move instruction.
  1723.  
  1724.    We call here when INSN is an insn to examine or store into a bit-field.
  1725.    BODY is the SET-rtx to be altered.
  1726.  
  1727.    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  1728.    (Currently this is called only from function.c, and EQUIV_MEM
  1729.    is always 0.)  */
  1730.  
  1731. static void
  1732. optimize_bit_field (body, insn, equiv_mem)
  1733.      rtx body;
  1734.      rtx insn;
  1735.      rtx *equiv_mem;
  1736. {
  1737.   register rtx bitfield;
  1738.   int destflag;
  1739.   rtx seq = 0;
  1740.   enum machine_mode mode;
  1741.  
  1742.   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  1743.       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  1744.     bitfield = SET_DEST (body), destflag = 1;
  1745.   else
  1746.     bitfield = SET_SRC (body), destflag = 0;
  1747.  
  1748.   /* First check that the field being stored has constant size and position
  1749.      and is in fact a byte or halfword suitably aligned.  */
  1750.  
  1751.   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  1752.       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  1753.       && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
  1754.       != BLKmode)
  1755.       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  1756.     {
  1757.       register rtx memref = 0;
  1758.  
  1759.       /* Now check that the containing word is memory, not a register,
  1760.      and that it is safe to change the machine mode.  */
  1761.  
  1762.       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  1763.     memref = XEXP (bitfield, 0);
  1764.       else if (GET_CODE (XEXP (bitfield, 0)) == REG
  1765.            && equiv_mem != 0)
  1766.     memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
  1767.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  1768.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  1769.     memref = SUBREG_REG (XEXP (bitfield, 0));
  1770.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  1771.            && equiv_mem != 0
  1772.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
  1773.     memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
  1774.  
  1775.       if (memref
  1776.       && ! mode_dependent_address_p (XEXP (memref, 0))
  1777.       && ! MEM_VOLATILE_P (memref))
  1778.     {
  1779.       /* Now adjust the address, first for any subreg'ing
  1780.          that we are now getting rid of,
  1781.          and then for which byte of the word is wanted.  */
  1782.  
  1783.       register int offset = INTVAL (XEXP (bitfield, 2));
  1784.       /* Adjust OFFSET to count bits from low-address byte.  */
  1785. #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
  1786.       offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
  1787.             - offset - INTVAL (XEXP (bitfield, 1)));
  1788. #endif
  1789.       /* Adjust OFFSET to count bytes from low-address byte.  */
  1790.       offset /= BITS_PER_UNIT;
  1791.       if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  1792.         {
  1793.           offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  1794. #if BYTES_BIG_ENDIAN
  1795.           offset -= (MIN (UNITS_PER_WORD,
  1796.                   GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  1797.              - MIN (UNITS_PER_WORD,
  1798.                 GET_MODE_SIZE (GET_MODE (memref))));
  1799. #endif
  1800.         }
  1801.  
  1802.       memref = change_address (memref, mode, 
  1803.                    plus_constant (XEXP (memref, 0), offset));
  1804.  
  1805.       /* Store this memory reference where
  1806.          we found the bit field reference.  */
  1807.  
  1808.       if (destflag)
  1809.         {
  1810.           validate_change (insn, &SET_DEST (body), memref, 1);
  1811.           if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  1812.         {
  1813.           rtx src = SET_SRC (body);
  1814.           while (GET_CODE (src) == SUBREG
  1815.              && SUBREG_WORD (src) == 0)
  1816.             src = SUBREG_REG (src);
  1817.           if (GET_MODE (src) != GET_MODE (memref))
  1818.             src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
  1819.           validate_change (insn, &SET_SRC (body), src, 1);
  1820.         }
  1821.           else if (GET_MODE (SET_SRC (body)) != VOIDmode
  1822.                && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  1823.         /* This shouldn't happen because anything that didn't have
  1824.            one of these modes should have got converted explicitly
  1825.            and then referenced through a subreg.
  1826.            This is so because the original bit-field was
  1827.            handled by agg_mode and so its tree structure had
  1828.            the same mode that memref now has.  */
  1829.         abort ();
  1830.         }
  1831.       else
  1832.         {
  1833.           rtx dest = SET_DEST (body);
  1834.  
  1835.           while (GET_CODE (dest) == SUBREG
  1836.              && SUBREG_WORD (dest) == 0)
  1837.         dest = SUBREG_REG (dest);
  1838.  
  1839.           validate_change (insn, &SET_DEST (body), dest, 1);
  1840.  
  1841.           if (GET_MODE (dest) == GET_MODE (memref))
  1842.         validate_change (insn, &SET_SRC (body), memref, 1);
  1843.           else
  1844.         {
  1845.           /* Convert the mem ref to the destination mode.  */
  1846.           rtx newreg = gen_reg_rtx (GET_MODE (dest));
  1847.  
  1848.           start_sequence ();
  1849.           convert_move (newreg, memref,
  1850.                 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
  1851.           seq = get_insns ();
  1852.           end_sequence ();
  1853.  
  1854.           validate_change (insn, &SET_SRC (body), newreg, 1);
  1855.         }
  1856.         }
  1857.  
  1858.       /* See if we can convert this extraction or insertion into
  1859.          a simple move insn.  We might not be able to do so if this
  1860.          was, for example, part of a PARALLEL.
  1861.  
  1862.          If we succeed, write out any needed conversions.  If we fail,
  1863.          it is hard to guess why we failed, so don't do anything
  1864.          special; just let the optimization be suppressed.  */
  1865.  
  1866.       if (apply_change_group () && seq)
  1867.         emit_insns_before (seq, insn);
  1868.     }
  1869.     }
  1870. }
  1871.  
  1872. /* These routines are responsible for converting virtual register references
  1873.    to the actual hard register references once RTL generation is complete.
  1874.  
  1875.    The following four variables are used for communication between the
  1876.    routines.  They contain the offsets of the virtual registers from their
  1877.    respective hard registers.  */
  1878.  
  1879. static int in_arg_offset;
  1880. static int var_offset;
  1881. static int dynamic_offset;
  1882. static int out_arg_offset;
  1883.  
  1884. /* In most machines, the stack pointer register is equivalent to the bottom
  1885.    of the stack.  */
  1886.  
  1887. #ifndef STACK_POINTER_OFFSET
  1888. #define STACK_POINTER_OFFSET    0
  1889. #endif
  1890.  
  1891. /* If not defined, pick an appropriate default for the offset of dynamically
  1892.    allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
  1893.    REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE.  */
  1894.  
  1895. #ifndef STACK_DYNAMIC_OFFSET
  1896.  
  1897. #ifdef ACCUMULATE_OUTGOING_ARGS
  1898. /* The bottom of the stack points to the actual arguments.  If
  1899.    REG_PARM_STACK_SPACE is defined, this includes the space for the register
  1900.    parameters.  However, if OUTGOING_REG_PARM_STACK space is not defined,
  1901.    stack space for register parameters is not pushed by the caller, but 
  1902.    rather part of the fixed stack areas and hence not included in
  1903.    `current_function_outgoing_args_size'.  Nevertheless, we must allow
  1904.    for it when allocating stack dynamic objects.  */
  1905.  
  1906. #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
  1907. #define STACK_DYNAMIC_OFFSET(FNDECL)    \
  1908. (current_function_outgoing_args_size    \
  1909.  + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
  1910.  
  1911. #else
  1912. #define STACK_DYNAMIC_OFFSET(FNDECL)    \
  1913. (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
  1914. #endif
  1915.  
  1916. #else
  1917. #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
  1918. #endif
  1919. #endif
  1920.  
  1921. /* Pass through the INSNS of function FNDECL and convert virtual register
  1922.    references to hard register references.  */
  1923.  
  1924. void
  1925. instantiate_virtual_regs (fndecl, insns)
  1926.      tree fndecl;
  1927.      rtx insns;
  1928. {
  1929.   rtx insn;
  1930.  
  1931.   /* Compute the offsets to use for this function.  */
  1932.   in_arg_offset = FIRST_PARM_OFFSET (fndecl);
  1933.   var_offset = STARTING_FRAME_OFFSET;
  1934.   dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
  1935.   out_arg_offset = STACK_POINTER_OFFSET;
  1936.  
  1937.   /* Scan all variables and parameters of this function.  For each that is
  1938.      in memory, instantiate all virtual registers if the result is a valid
  1939.      address.  If not, we do it later.  That will handle most uses of virtual
  1940.      regs on many machines.  */
  1941.   instantiate_decls (fndecl, 1);
  1942.  
  1943.   /* Initialize recognition, indicating that volatile is OK.  */
  1944.   init_recog ();
  1945.  
  1946.   /* Scan through all the insns, instantiating every virtual register still
  1947.      present.  */
  1948.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  1949.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  1950.     || GET_CODE (insn) == CALL_INSN)
  1951.       {
  1952.     instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
  1953.     instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
  1954.       }
  1955.  
  1956.   /* Now instantiate the remaining register equivalences for debugging info.
  1957.      These will not be valid addresses.  */
  1958.   instantiate_decls (fndecl, 0);
  1959.  
  1960.   /* Indicate that, from now on, assign_stack_local should use
  1961.      frame_pointer_rtx.  */
  1962.   virtuals_instantiated = 1;
  1963. }
  1964.  
  1965. /* Scan all decls in FNDECL (both variables and parameters) and instantiate
  1966.    all virtual registers in their DECL_RTL's.
  1967.  
  1968.    If VALID_ONLY, do this only if the resulting address is still valid.
  1969.    Otherwise, always do it.  */
  1970.  
  1971. static void
  1972. instantiate_decls (fndecl, valid_only)
  1973.      tree fndecl;
  1974.      int valid_only;
  1975. {
  1976.   tree decl;
  1977.  
  1978.   if (DECL_INLINE (fndecl))
  1979.     /* When compiling an inline function, the obstack used for
  1980.        rtl allocation is the maybepermanent_obstack.  Calling
  1981.        `resume_temporary_allocation' switches us back to that
  1982.        obstack while we process this function's parameters.  */
  1983.     resume_temporary_allocation ();
  1984.  
  1985.   /* Process all parameters of the function.  */
  1986.   for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
  1987.     {
  1988.       instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
  1989.             valid_only);    
  1990.       instantiate_decl (DECL_INCOMING_RTL (decl),
  1991.             int_size_in_bytes (TREE_TYPE (decl)), valid_only);
  1992.     }
  1993.  
  1994.   /* Now process all variables defined in the function or its subblocks. */
  1995.   instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
  1996.  
  1997.   if (DECL_INLINE (fndecl))
  1998.     {
  1999.       /* Save all rtl allocated for this function by raising the
  2000.      high-water mark on the maybepermanent_obstack.  */
  2001.       preserve_data ();
  2002.       /* All further rtl allocation is now done in the current_obstack.  */
  2003.       rtl_in_current_obstack ();
  2004.     }
  2005. }
  2006.  
  2007. /* Subroutine of instantiate_decls: Process all decls in the given
  2008.    BLOCK node and all its subblocks.  */
  2009.  
  2010. static void
  2011. instantiate_decls_1 (let, valid_only)
  2012.      tree let;
  2013.      int valid_only;
  2014. {
  2015.   tree t;
  2016.  
  2017.   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
  2018.     instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
  2019.               valid_only);
  2020.  
  2021.   /* Process all subblocks.  */
  2022.   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
  2023.     instantiate_decls_1 (t, valid_only);
  2024. }
  2025.  
  2026. /* Subroutine of the preceeding procedures: Given RTL representing a
  2027.    decl and the size of the object, do any instantiation required.
  2028.  
  2029.    If VALID_ONLY is non-zero, it means that the RTL should only be
  2030.    changed if the new address is valid.  */
  2031.  
  2032. static void
  2033. instantiate_decl (x, size, valid_only)
  2034.      rtx x;
  2035.      int size;
  2036.      int valid_only;
  2037. {
  2038.   enum machine_mode mode;
  2039.   rtx addr;
  2040.  
  2041.   /* If this is not a MEM, no need to do anything.  Similarly if the
  2042.      address is a constant or a register that is not a virtual register.  */
  2043.  
  2044.   if (x == 0 || GET_CODE (x) != MEM)
  2045.     return;
  2046.  
  2047.   addr = XEXP (x, 0);
  2048.   if (CONSTANT_P (addr)
  2049.       || (GET_CODE (addr) == REG
  2050.       && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
  2051.           || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
  2052.     return;
  2053.  
  2054.   /* If we should only do this if the address is valid, copy the address.
  2055.      We need to do this so we can undo any changes that might make the
  2056.      address invalid.  This copy is unfortunate, but probably can't be
  2057.      avoided.  */
  2058.  
  2059.   if (valid_only)
  2060.     addr = copy_rtx (addr);
  2061.  
  2062.   instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
  2063.  
  2064.   if (! valid_only)
  2065.     return;
  2066.  
  2067.   /* Now verify that the resulting address is valid for every integer or
  2068.      floating-point mode up to and including SIZE bytes long.  We do this
  2069.      since the object might be accessed in any mode and frame addresses
  2070.      are shared.  */
  2071.  
  2072.   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  2073.        mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
  2074.        mode = GET_MODE_WIDER_MODE (mode))
  2075.     if (! memory_address_p (mode, addr))
  2076.       return;
  2077.  
  2078.   for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
  2079.        mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
  2080.        mode = GET_MODE_WIDER_MODE (mode))
  2081.     if (! memory_address_p (mode, addr))
  2082.       return;
  2083.  
  2084.   /* Otherwise, put back the address, now that we have updated it and we
  2085.      know it is valid.  */
  2086.  
  2087.   XEXP (x, 0) = addr;
  2088. }
  2089.  
  2090. /* Given a pointer to a piece of rtx and an optional pointer to the
  2091.    containing object, instantiate any virtual registers present in it.
  2092.  
  2093.    If EXTRA_INSNS, we always do the replacement and generate
  2094.    any extra insns before OBJECT.  If it zero, we do nothing if replacement
  2095.    is not valid.
  2096.  
  2097.    Return 1 if we either had nothing to do or if we were able to do the
  2098.    needed replacement.  Return 0 otherwise; we only return zero if 
  2099.    EXTRA_INSNS is zero.
  2100.  
  2101.    We first try some simple transformations to avoid the creation of extra
  2102.    pseudos.  */
  2103.  
  2104. static int
  2105. instantiate_virtual_regs_1 (loc, object, extra_insns)
  2106.      rtx *loc;
  2107.      rtx object;
  2108.      int extra_insns;
  2109. {
  2110.   rtx x;
  2111.   RTX_CODE code;
  2112.   rtx new = 0;
  2113.   int offset;
  2114.   rtx temp;
  2115.   rtx seq;
  2116.   int i, j;
  2117.   char *fmt;
  2118.  
  2119.   /* Re-start here to avoid recursion in common cases.  */
  2120.  restart:
  2121.  
  2122.   x = *loc;
  2123.   if (x == 0)
  2124.     return 1;
  2125.  
  2126.   code = GET_CODE (x);
  2127.  
  2128.   /* Check for some special cases.  */
  2129.   switch (code)
  2130.     {
  2131.     case CONST_INT:
  2132.     case CONST_DOUBLE:
  2133.     case CONST:
  2134.     case SYMBOL_REF:
  2135.     case CODE_LABEL:
  2136.     case PC:
  2137.     case CC0:
  2138.     case ASM_INPUT:
  2139.     case ADDR_VEC:
  2140.     case ADDR_DIFF_VEC:
  2141.     case RETURN:
  2142.       return 1;
  2143.  
  2144.     case SET:
  2145.       /* We are allowed to set the virtual registers.  This means that
  2146.      that the actual register should receive the source minus the
  2147.      appropriate offset.  This is used, for example, in the handling
  2148.      of non-local gotos.  */
  2149.       if (SET_DEST (x) == virtual_incoming_args_rtx)
  2150.     new = arg_pointer_rtx, offset = - in_arg_offset;
  2151.       else if (SET_DEST (x) == virtual_stack_vars_rtx)
  2152.     new = frame_pointer_rtx, offset = - var_offset;
  2153.       else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
  2154.     new = stack_pointer_rtx, offset = - dynamic_offset;
  2155.       else if (SET_DEST (x) == virtual_outgoing_args_rtx)
  2156.     new = stack_pointer_rtx, offset = - out_arg_offset;
  2157.  
  2158.       if (new)
  2159.     {
  2160.       /* The only valid sources here are PLUS or REG.  Just do
  2161.          the simplest possible thing to handle them.  */
  2162.       if (GET_CODE (SET_SRC (x)) != REG
  2163.           && GET_CODE (SET_SRC (x)) != PLUS)
  2164.         abort ();
  2165.  
  2166.       start_sequence ();
  2167.       if (GET_CODE (SET_SRC (x)) != REG)
  2168.         temp = force_operand (SET_SRC (x), NULL_RTX);
  2169.       else
  2170.         temp = SET_SRC (x);
  2171.       temp = force_operand (plus_constant (temp, offset), NULL_RTX);
  2172.       seq = get_insns ();
  2173.       end_sequence ();
  2174.  
  2175.       emit_insns_before (seq, object);
  2176.       SET_DEST (x) = new;
  2177.  
  2178.       if (!validate_change (object, &SET_SRC (x), temp, 0)
  2179.           || ! extra_insns)
  2180.         abort ();
  2181.  
  2182.       return 1;
  2183.     }
  2184.  
  2185.       instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
  2186.       loc = &SET_SRC (x);
  2187.       goto restart;
  2188.  
  2189.     case PLUS:
  2190.       /* Handle special case of virtual register plus constant.  */
  2191.       if (CONSTANT_P (XEXP (x, 1)))
  2192.     {
  2193.       rtx old;
  2194.  
  2195.       /* Check for (plus (plus VIRT foo) (const_int)) first.  */
  2196.       if (GET_CODE (XEXP (x, 0)) == PLUS)
  2197.         {
  2198.           rtx inner = XEXP (XEXP (x, 0), 0);
  2199.  
  2200.           if (inner == virtual_incoming_args_rtx)
  2201.         new = arg_pointer_rtx, offset = in_arg_offset;
  2202.           else if (inner == virtual_stack_vars_rtx)
  2203.         new = frame_pointer_rtx, offset = var_offset;
  2204.           else if (inner == virtual_stack_dynamic_rtx)
  2205.         new = stack_pointer_rtx, offset = dynamic_offset;
  2206.           else if (inner == virtual_outgoing_args_rtx)
  2207.         new = stack_pointer_rtx, offset = out_arg_offset;
  2208.           else
  2209.         {
  2210.           loc = &XEXP (x, 0);
  2211.           goto restart;
  2212.         }
  2213.  
  2214.           instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
  2215.                       extra_insns);
  2216.           new = gen_rtx (PLUS, DPmode, new, XEXP (XEXP (x, 0), 1));
  2217.         }
  2218.  
  2219.       else if (XEXP (x, 0) == virtual_incoming_args_rtx)
  2220.         new = arg_pointer_rtx, offset = in_arg_offset;
  2221.       else if (XEXP (x, 0) == virtual_stack_vars_rtx)
  2222.         new = frame_pointer_rtx, offset = var_offset;
  2223.       else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
  2224.         new = stack_pointer_rtx, offset = dynamic_offset;
  2225.       else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
  2226.         new = stack_pointer_rtx, offset = out_arg_offset;
  2227.       else
  2228.         {
  2229.           /* We know the second operand is a constant.  Unless the
  2230.          first operand is a REG (which has been already checked),
  2231.          it needs to be checked.  */
  2232.           if (GET_CODE (XEXP (x, 0)) != REG)
  2233.         {
  2234.           loc = &XEXP (x, 0);
  2235.           goto restart;
  2236.         }
  2237.           return 1;
  2238.         }
  2239.  
  2240.       old = XEXP (x, 0);
  2241.       XEXP (x, 0) = new;
  2242.       new = plus_constant (XEXP (x, 1), offset);
  2243.  
  2244.       /* If the new constant is zero, try to replace the sum with its
  2245.          first operand.  */
  2246.       if (new == const0_rtx
  2247.           && validate_change (object, loc, XEXP (x, 0), 0))
  2248.         return 1;
  2249.  
  2250.       /* Next try to replace constant with new one.  */
  2251.       if (!validate_change (object, &XEXP (x, 1), new, 0))
  2252.         {
  2253.           if (! extra_insns)
  2254.         {
  2255.           XEXP (x, 0) = old;
  2256.           return 0;
  2257.         }
  2258.  
  2259.           /* Otherwise copy the new constant into a register and replace
  2260.          constant with that register.  */
  2261.           temp = gen_reg_rtx (DPmode);
  2262.           if (validate_change (object, &XEXP (x, 1), temp, 0))
  2263.         emit_insn_before (gen_move_insn (temp, new), object);
  2264.           else
  2265.         {
  2266.           /* If that didn't work, replace this expression with a
  2267.              register containing the sum.  */
  2268.  
  2269.           new = gen_rtx (PLUS, DPmode, XEXP (x, 0), new);
  2270.           XEXP (x, 0) = old;
  2271.  
  2272.           start_sequence ();
  2273.           temp = force_operand (new, NULL_RTX);
  2274.           seq = get_insns ();
  2275.           end_sequence ();
  2276.  
  2277.           emit_insns_before (seq, object);
  2278.           if (! validate_change (object, loc, temp, 0)
  2279.               && ! validate_replace_rtx (x, temp, object))
  2280.             abort ();
  2281.         }
  2282.         }
  2283.  
  2284.       return 1;
  2285.     }
  2286.  
  2287.       /* Fall through to generic two-operand expression case.  */
  2288.     case EXPR_LIST:
  2289.     case CALL:
  2290.     case COMPARE:
  2291.     case MINUS:
  2292.     case MULT:
  2293.     case DIV:      case UDIV:
  2294.     case MOD:      case UMOD:
  2295.     case AND:      case IOR:      case XOR:
  2296.     case LSHIFT:   case ASHIFT:   case ROTATE:
  2297.     case ASHIFTRT: case LSHIFTRT: case ROTATERT:
  2298.     case NE:       case EQ:
  2299.     case GE:       case GT:       case GEU:    case GTU:
  2300.     case LE:       case LT:       case LEU:    case LTU:
  2301.       if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
  2302.     instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
  2303.       loc = &XEXP (x, 0);
  2304.       goto restart;
  2305.  
  2306.     case MEM:
  2307.       /* Most cases of MEM that convert to valid addresses have already been
  2308.      handled by our scan of regno_reg_rtx.  The only special handling we
  2309.      need here is to make a copy of the rtx to ensure it isn't being
  2310.      shared if we have to change it to a pseudo. 
  2311.  
  2312.      If the rtx is a simple reference to an address via a virtual register,
  2313.      it can potentially be shared.  In such cases, first try to make it
  2314.      a valid address, which can also be shared.  Otherwise, copy it and
  2315.      proceed normally. 
  2316.  
  2317.      First check for common cases that need no processing.  These are
  2318.      usually due to instantiation already being done on a previous instance
  2319.      of a shared rtx.  */
  2320.  
  2321.       temp = XEXP (x, 0);
  2322.       if (CONSTANT_ADDRESS_P (temp)
  2323. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2324.       || temp == arg_pointer_rtx
  2325. #endif
  2326.       || temp == frame_pointer_rtx)
  2327.     return 1;
  2328.  
  2329.       if (GET_CODE (temp) == PLUS
  2330.       && CONSTANT_ADDRESS_P (XEXP (temp, 1))
  2331.       && (XEXP (temp, 0) == frame_pointer_rtx
  2332. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2333.           || XEXP (temp, 0) == arg_pointer_rtx
  2334. #endif
  2335.           ))
  2336.     return 1;
  2337.  
  2338.       if (temp == virtual_stack_vars_rtx
  2339.       || temp == virtual_incoming_args_rtx
  2340.       || (GET_CODE (temp) == PLUS
  2341.           && CONSTANT_ADDRESS_P (XEXP (temp, 1))
  2342.           && (XEXP (temp, 0) == virtual_stack_vars_rtx
  2343.           || XEXP (temp, 0) == virtual_incoming_args_rtx)))
  2344.     {
  2345.       /* This MEM may be shared.  If the substitution can be done without
  2346.          the need to generate new pseudos, we want to do it in place
  2347.          so all copies of the shared rtx benefit.  The call below will
  2348.          only make substitutions if the resulting address is still
  2349.          valid.
  2350.  
  2351.          Note that we cannot pass X as the object in the recursive call
  2352.          since the insn being processed may not allow all valid
  2353.          addresses.  However, if we were not passed on object, we can
  2354.          only modify X without copying it if X will have a valid
  2355.          address.
  2356.  
  2357.          ??? Also note that this can still lose if OBJECT is an insn that
  2358.          has less restrictions on an address that some other insn.
  2359.          In that case, we will modify the shared address.  This case
  2360.          doesn't seem very likely, though.  */
  2361.  
  2362.       if (instantiate_virtual_regs_1 (&XEXP (x, 0),
  2363.                       object ? object : x, 0))
  2364.         return 1;
  2365.  
  2366.       /* Otherwise make a copy and process that copy.  We copy the entire
  2367.          RTL expression since it might be a PLUS which could also be
  2368.          shared.  */
  2369.       *loc = x = copy_rtx (x);
  2370.     }
  2371.  
  2372.       /* Fall through to generic unary operation case.  */
  2373.     case USE:
  2374.     case CLOBBER:
  2375.     case SUBREG:
  2376.     case STRICT_LOW_PART:
  2377.     case NEG:          case NOT:
  2378.     case PRE_DEC:      case PRE_INC:      case POST_DEC:    case POST_INC:
  2379.     case SIGN_EXTEND:  case ZERO_EXTEND:
  2380.     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
  2381.     case FLOAT:        case FIX:
  2382.     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
  2383.     case ABS:
  2384.     case SQRT:
  2385.     case FFS:
  2386.       /* These case either have just one operand or we know that we need not
  2387.      check the rest of the operands.  */
  2388.       loc = &XEXP (x, 0);
  2389.       goto restart;
  2390.  
  2391.     case REG:
  2392.       /* Try to replace with a PLUS.  If that doesn't work, compute the sum
  2393.      in front of this insn and substitute the temporary.  */
  2394.       if (x == virtual_incoming_args_rtx)
  2395.     new = arg_pointer_rtx, offset = in_arg_offset;
  2396.       else if (x == virtual_stack_vars_rtx)
  2397.     new = frame_pointer_rtx, offset = var_offset;
  2398.       else if (x == virtual_stack_dynamic_rtx)
  2399.     new = stack_pointer_rtx, offset = dynamic_offset;
  2400.       else if (x == virtual_outgoing_args_rtx)
  2401.     new = stack_pointer_rtx, offset = out_arg_offset;
  2402.  
  2403.       if (new)
  2404.     {
  2405.       temp = plus_constant (new, offset);
  2406.       if (!validate_change (object, loc, temp, 0))
  2407.         {
  2408.           if (! extra_insns)
  2409.         return 0;
  2410.  
  2411.           start_sequence ();
  2412.           temp = force_operand (temp, NULL_RTX);
  2413.           seq = get_insns ();
  2414.           end_sequence ();
  2415.  
  2416.           emit_insns_before (seq, object);
  2417.           if (! validate_change (object, loc, temp, 0)
  2418.           && ! validate_replace_rtx (x, temp, object))
  2419.         abort ();
  2420.         }
  2421.     }
  2422.  
  2423.       return 1;
  2424.     }
  2425.  
  2426.   /* Scan all subexpressions.  */
  2427.   fmt = GET_RTX_FORMAT (code);
  2428.   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  2429.     if (*fmt == 'e')
  2430.       {
  2431.     if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
  2432.       return 0;
  2433.       }
  2434.     else if (*fmt == 'E')
  2435.       for (j = 0; j < XVECLEN (x, i); j++)
  2436.     if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
  2437.                       extra_insns))
  2438.       return 0;
  2439.  
  2440.   return 1;
  2441. }
  2442.  
  2443. /* Optimization: assuming this function does not receive nonlocal gotos,
  2444.    delete the handlers for such, as well as the insns to establish
  2445.    and disestablish them.  */
  2446.  
  2447. static void
  2448. delete_handlers ()
  2449. {
  2450.   rtx insn;
  2451.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  2452.     {
  2453.       /* Delete the handler by turning off the flag that would
  2454.      prevent jump_optimize from deleting it.
  2455.      Also permit deletion of the nonlocal labels themselves
  2456.      if nothing local refers to them.  */
  2457.       if (GET_CODE (insn) == CODE_LABEL)
  2458.     LABEL_PRESERVE_P (insn) = 0;
  2459.       if (GET_CODE (insn) == INSN
  2460.       && ((nonlocal_goto_handler_slot != 0
  2461.            && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
  2462.           || (nonlocal_goto_stack_level != 0
  2463.           && reg_mentioned_p (nonlocal_goto_stack_level,
  2464.                       PATTERN (insn)))))
  2465.     delete_insn (insn);
  2466.     }
  2467. }
  2468.  
  2469. /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
  2470.    of the current function.  */
  2471.  
  2472. rtx
  2473. nonlocal_label_rtx_list ()
  2474. {
  2475.   tree t;
  2476.   rtx x = 0;
  2477.  
  2478.   for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
  2479.     x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
  2480.  
  2481.   return x;
  2482. }
  2483.  
  2484. /* Output a USE for any register use in RTL.
  2485.    This is used with -noreg to mark the extent of lifespan
  2486.    of any registers used in a user-visible variable's DECL_RTL.  */
  2487.  
  2488. void
  2489. use_variable (rtl)
  2490.      rtx rtl;
  2491. {
  2492.   if (GET_CODE (rtl) == REG)
  2493.     /* This is a register variable.  */
  2494.     emit_insn (gen_rtx (USE, VOIDmode, rtl));
  2495.   else if (GET_CODE (rtl) == MEM
  2496.        && GET_CODE (XEXP (rtl, 0)) == REG
  2497.        && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
  2498.            || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
  2499.        && XEXP (rtl, 0) != current_function_internal_arg_pointer)
  2500.     /* This is a variable-sized structure.  */
  2501.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
  2502. }
  2503.  
  2504. /* Like use_variable except that it outputs the USEs after INSN
  2505.    instead of at the end of the insn-chain.  */
  2506.  
  2507. void
  2508. use_variable_after (rtl, insn)
  2509.      rtx rtl, insn;
  2510. {
  2511.   if (GET_CODE (rtl) == REG)
  2512.     /* This is a register variable.  */
  2513.     emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
  2514.   else if (GET_CODE (rtl) == MEM
  2515.        && GET_CODE (XEXP (rtl, 0)) == REG
  2516.        && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
  2517.            || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
  2518.        && XEXP (rtl, 0) != current_function_internal_arg_pointer)
  2519.     /* This is a variable-sized structure.  */
  2520.     emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
  2521. }
  2522.  
  2523. int
  2524. max_parm_reg_num ()
  2525. {
  2526.   return max_parm_reg;
  2527. }
  2528.  
  2529. /* Return the first insn following those generated by `assign_parms'.  */
  2530.  
  2531. rtx
  2532. get_first_nonparm_insn ()
  2533. {
  2534.   if (last_parm_insn)
  2535.     return NEXT_INSN (last_parm_insn);
  2536.   return get_insns ();
  2537. }
  2538.  
  2539. /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
  2540.    Crash if there is none.  */
  2541.  
  2542. rtx
  2543. get_first_block_beg ()
  2544. {
  2545.   register rtx searcher;
  2546.   register rtx insn = get_first_nonparm_insn ();
  2547.  
  2548.   for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
  2549.     if (GET_CODE (searcher) == NOTE
  2550.     && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
  2551.       return searcher;
  2552.  
  2553.   abort ();    /* Invalid call to this function.  (See comments above.)  */
  2554.   return NULL_RTX;
  2555. }
  2556.  
  2557. /* Return 1 if EXP returns an aggregate value, for which an address
  2558.    must be passed to the function or returned by the function.  */
  2559.  
  2560. int
  2561. aggregate_value_p (exp)
  2562.      tree exp;
  2563. {
  2564.   int i, regno, nregs;
  2565.   rtx reg;
  2566.   if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
  2567.     return 1;
  2568.   if (RETURN_IN_MEMORY (TREE_TYPE (exp)))
  2569.     return 1;
  2570.   if (flag_pcc_struct_return
  2571.       && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
  2572.       || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE))
  2573.     return 1;
  2574.   /* Make sure we have suitable call-clobbered regs to return
  2575.      the value in; if not, we must return it in memory.  */
  2576.   reg = hard_function_value (TREE_TYPE (exp), 0);
  2577.   regno = REGNO (reg);
  2578.   nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (TREE_TYPE (exp)));
  2579.   for (i = 0; i < nregs; i++)
  2580.     if (! call_used_regs[regno + i])
  2581.       return 1;
  2582.   return 0;
  2583. }
  2584.  
  2585. /* Assign RTL expressions to the function's parameters.
  2586.    This may involve copying them into registers and using
  2587.    those registers as the RTL for them.
  2588.  
  2589.    If SECOND_TIME is non-zero it means that this function is being
  2590.    called a second time.  This is done by integrate.c when a function's
  2591.    compilation is deferred.  We need to come back here in case the
  2592.    FUNCTION_ARG macro computes items needed for the rest of the compilation
  2593.    (such as changing which registers are fixed or caller-saved).  But suppress
  2594.    writing any insns or setting DECL_RTL of anything in this case.  */
  2595.  
  2596. void
  2597. assign_parms (fndecl, second_time)
  2598.      tree fndecl;
  2599.      int second_time;
  2600. {
  2601.   register tree parm;
  2602.   register rtx entry_parm = 0;
  2603.   register rtx stack_parm = 0;
  2604.   CUMULATIVE_ARGS args_so_far;
  2605.   enum machine_mode promoted_mode, passed_mode, nominal_mode;
  2606.   int unsignedp;
  2607.   /* Total space needed so far for args on the stack,
  2608.      given as a constant and a tree-expression.  */
  2609.   struct args_size stack_args_size;
  2610.   tree fntype = TREE_TYPE (fndecl);
  2611.   tree fnargs = DECL_ARGUMENTS (fndecl);
  2612.   /* This is used for the arg pointer when referring to stack args.  */
  2613.   rtx internal_arg_pointer;
  2614.   /* This is a dummy PARM_DECL that we used for the function result if 
  2615.      the function returns a structure.  */
  2616.   tree function_result_decl = 0;
  2617.   int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
  2618.   int varargs_setup = 0;
  2619.  
  2620.   /* Nonzero if the last arg is named `__builtin_va_alist',
  2621.      which is used on some machines for old-fashioned non-ANSI varargs.h;
  2622.      this should be stuck onto the stack as if it had arrived there.  */
  2623.   int vararg
  2624.     = (fnargs
  2625.        && (parm = tree_last (fnargs)) != 0
  2626.        && DECL_NAME (parm)
  2627.        && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
  2628.              "__builtin_va_alist")));
  2629.  
  2630.   /* Nonzero if function takes extra anonymous args.
  2631.      This means the last named arg must be on the stack
  2632.      right before the anonymous ones. */
  2633.   int stdarg
  2634.     = (TYPE_ARG_TYPES (fntype) != 0
  2635.        && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  2636.        != void_type_node));
  2637.  
  2638.   /* If the reg that the virtual arg pointer will be translated into is
  2639.      not a fixed reg or is the stack pointer, make a copy of the virtual
  2640.      arg pointer, and address parms via the copy.  The frame pointer is
  2641.      considered fixed even though it is not marked as such.
  2642.  
  2643.      The second time through, simply use ap to avoid generating rtx.  */
  2644.  
  2645.   if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
  2646.        || ! (fixed_regs[ARG_POINTER_REGNUM]
  2647.          || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
  2648.       && ! second_time)
  2649.     internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
  2650.   else
  2651.     internal_arg_pointer = virtual_incoming_args_rtx;
  2652.   current_function_internal_arg_pointer = internal_arg_pointer;
  2653.  
  2654.   stack_args_size.constant = 0;
  2655.   stack_args_size.var = 0;
  2656.  
  2657.   /* If struct value address is treated as the first argument, make it so.  */
  2658.   if (aggregate_value_p (DECL_RESULT (fndecl))
  2659.       && ! current_function_returns_pcc_struct
  2660.       && struct_value_incoming_rtx == 0)
  2661.     {
  2662.       tree type = build_pointer_type (fntype);
  2663.  
  2664.       function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
  2665.  
  2666.       DECL_ARG_TYPE (function_result_decl) = type;
  2667.       TREE_CHAIN (function_result_decl) = fnargs;
  2668.       fnargs = function_result_decl;
  2669.     }
  2670.                    
  2671.   parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  2672.   bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
  2673.  
  2674. #ifdef INIT_CUMULATIVE_INCOMING_ARGS
  2675.   INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_PTR);
  2676. #else
  2677.   INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_PTR);
  2678. #endif
  2679.  
  2680.   /* If we're compiling a pascal-declared function, reverse the order
  2681.      of the declared arguments before doing anything with them.
  2682.      They will be reversed back at the bottom of the loop. */
  2683.   if (current_function_is_pascal)
  2684.     fnargs = DECL_ARGUMENTS (fndecl) = nreverse (DECL_ARGUMENTS (fndecl));
  2685.  
  2686.   /* We haven't yet found an argument that we must push and pretend the
  2687.      caller did.  */
  2688.   current_function_pretend_args_size = 0;
  2689.  
  2690.   for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
  2691.     {
  2692.       int aggregate
  2693.     = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
  2694.        || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
  2695.        || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE);
  2696.       struct args_size stack_offset;
  2697.       struct args_size arg_size;
  2698.       int passed_pointer = 0;
  2699.       tree passed_type = DECL_ARG_TYPE (parm);
  2700.  
  2701.       /* Set LAST_NAMED if this is last named arg before some
  2702.      anonymous args.  We treat it as if it were anonymous too.  */
  2703.       int last_named = ((TREE_CHAIN (parm) == 0
  2704.              || DECL_NAME (TREE_CHAIN (parm)) == 0)
  2705.             && (vararg || stdarg));
  2706.  
  2707.       if (TREE_TYPE (parm) == error_mark_node
  2708.       /* This can happen after weird syntax errors
  2709.          or if an enum type is defined among the parms.  */
  2710.       || TREE_CODE (parm) != PARM_DECL
  2711.       || passed_type == NULL)
  2712.     {
  2713.       DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
  2714.                                 const0_rtx);
  2715.       TREE_USED (parm) = 1;
  2716.       continue;
  2717.     }
  2718.       /* Pascal-declared fns need to undo promotions that were done
  2719.      during parsing.  Should be careful to undo only char/short
  2720.      -> int promotions. */
  2721.       if (current_function_is_pascal
  2722.       && TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE)
  2723.     passed_type = DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
  2724.  
  2725.       /* For varargs.h function, save info about regs and stack space
  2726.      used by the individual args, not including the va_alist arg.  */
  2727.       if (vararg && last_named)
  2728.     current_function_args_info = args_so_far;
  2729.  
  2730.       /* Find mode of arg as it is passed, and mode of arg
  2731.      as it should be during execution of this function.  */
  2732.       passed_mode = TYPE_MODE (passed_type);
  2733.       nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  2734.  
  2735.       /* If the parm's mode is VOID, its value doesn't matter,
  2736.      and avoid the usual things like emit_move_insn that could crash.  */
  2737.       if (nominal_mode == VOIDmode)
  2738.     {
  2739.       DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
  2740.       continue;
  2741.     }
  2742.  
  2743. #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
  2744.       /* See if this arg was passed by invisible reference.  */
  2745.       if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
  2746.                       passed_type, ! last_named))
  2747.     {
  2748.       passed_type = build_pointer_type (passed_type);
  2749.       passed_pointer = 1;
  2750.       passed_mode = nominal_mode = TPmode;
  2751.     }
  2752. #endif
  2753.  
  2754.       promoted_mode = passed_mode;
  2755.  
  2756. #ifdef PROMOTE_FUNCTION_ARGS
  2757.       /* Compute the mode in which the arg is actually extended to.  */
  2758.       if (TREE_CODE (passed_type) == INTEGER_TYPE
  2759.       || TREE_CODE (passed_type) == ENUMERAL_TYPE
  2760.       || TREE_CODE (passed_type) == BOOLEAN_TYPE
  2761.       || TREE_CODE (passed_type) == CHAR_TYPE
  2762.       || TREE_CODE (passed_type) == REAL_TYPE
  2763.       || TREE_CODE (passed_type) == POINTER_TYPE
  2764.       || TREE_CODE (passed_type) == OFFSET_TYPE)
  2765.     {
  2766.       unsignedp = TREE_UNSIGNED (passed_type);
  2767.       PROMOTE_MODE (promoted_mode, unsignedp, passed_type);
  2768.     }
  2769. #endif
  2770.  
  2771.       /* Let machine desc say which reg (if any) the parm arrives in.
  2772.      0 means it arrives on the stack.  */
  2773. #ifdef FUNCTION_INCOMING_ARG
  2774.       entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
  2775.                       passed_type, ! last_named);
  2776. #else
  2777.       entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
  2778.                  passed_type, ! last_named);
  2779. #endif
  2780.  
  2781.       if (entry_parm)
  2782.     passed_mode = promoted_mode;
  2783.  
  2784. #ifdef SETUP_INCOMING_VARARGS
  2785.       /* If this is the last named parameter, do any required setup for
  2786.      varargs or stdargs.  We need to know about the case of this being an
  2787.      addressable type, in which case we skip the registers it
  2788.      would have arrived in.
  2789.  
  2790.      For stdargs, LAST_NAMED will be set for two parameters, the one that
  2791.      is actually the last named, and the dummy parameter.  We only
  2792.      want to do this action once.
  2793.  
  2794.      Also, indicate when RTL generation is to be suppressed.  */
  2795.       if (last_named && !varargs_setup)
  2796.     {
  2797.       SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
  2798.                   current_function_pretend_args_size,
  2799.                   second_time);
  2800.       varargs_setup = 1;
  2801.     }
  2802. #endif
  2803.  
  2804.       /* Determine parm's home in the stack,
  2805.      in case it arrives in the stack or we should pretend it did.
  2806.  
  2807.      Compute the stack position and rtx where the argument arrives
  2808.      and its size.
  2809.  
  2810.      There is one complexity here:  If this was a parameter that would
  2811.      have been passed in registers, but wasn't only because it is
  2812.      __builtin_va_alist, we want locate_and_pad_parm to treat it as if
  2813.      it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
  2814.      In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
  2815.      0 as it was the previous time.  */
  2816.  
  2817.       locate_and_pad_parm (passed_mode, passed_type,
  2818. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  2819.                1,
  2820. #else
  2821. #ifdef FUNCTION_INCOMING_ARG
  2822.                FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  2823.                           passed_type,
  2824.                           (! last_named
  2825.                            || varargs_setup)) != 0,
  2826. #else
  2827.                FUNCTION_ARG (args_so_far, passed_mode,
  2828.                      passed_type,
  2829.                      ! last_named || varargs_setup) != 0,
  2830. #endif
  2831. #endif
  2832.                fndecl, &stack_args_size, &stack_offset, &arg_size);
  2833.  
  2834.       if (! second_time)
  2835.     {
  2836.       rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2837.  
  2838.       if (offset_rtx == const0_rtx)
  2839.         stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
  2840.       else
  2841.         stack_parm = gen_rtx (MEM, passed_mode,
  2842.                   gen_rtx (PLUS, DPmode,
  2843.                        internal_arg_pointer, offset_rtx));
  2844.  
  2845.       /* If this is a memory ref that contains aggregate components,
  2846.          mark it as such for cse and loop optimize.  */
  2847.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  2848.     }
  2849.  
  2850.       /* If this parameter was passed both in registers and in the stack,
  2851.      use the copy on the stack.  */
  2852.       if (MUST_PASS_IN_STACK (passed_mode, passed_type))
  2853.     entry_parm = 0;
  2854.  
  2855.       /* If this parm was passed part in regs and part in memory,
  2856.      pretend it arrived entirely in memory
  2857.      by pushing the register-part onto the stack.
  2858.  
  2859.      In the special case of a DImode or DFmode that is split,
  2860.      we could put it together in a pseudoreg directly,
  2861.      but for now that's not worth bothering with.  */
  2862.  
  2863.       if (entry_parm)
  2864.     {
  2865.       int nregs = 0;
  2866. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  2867.       nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  2868.                           passed_type, ! last_named);
  2869. #endif
  2870.  
  2871.       if (nregs > 0)
  2872.         {
  2873.           current_function_pretend_args_size
  2874.         = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  2875.            / (PARM_BOUNDARY / BITS_PER_UNIT)
  2876.            * (PARM_BOUNDARY / BITS_PER_UNIT));
  2877.  
  2878.           if (! second_time)
  2879.         move_block_from_reg (REGNO (entry_parm),
  2880.                      validize_mem (stack_parm), nregs);
  2881.           entry_parm = stack_parm;
  2882.         }
  2883.     }
  2884.  
  2885.       /* If we didn't decide this parm came in a register,
  2886.      by default it came on the stack.  */
  2887.       if (entry_parm == 0)
  2888.     entry_parm = stack_parm;
  2889.  
  2890.       /* Record permanently how this parm was passed.  */
  2891.       if (! second_time)
  2892.     DECL_INCOMING_RTL (parm) = entry_parm;
  2893.  
  2894.       /* If there is actually space on the stack for this parm,
  2895.      count it in stack_args_size; otherwise set stack_parm to 0
  2896.      to indicate there is no preallocated stack slot for the parm.  */
  2897.  
  2898.       if (entry_parm == stack_parm
  2899. #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
  2900.       /* On some machines, even if a parm value arrives in a register
  2901.          there is still an (uninitialized) stack slot allocated for it.
  2902.  
  2903.          ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
  2904.          whether this parameter already has a stack slot allocated,
  2905.          because an arg block exists only if current_function_args_size
  2906.          is larger than some threshhold, and we haven't calculated that
  2907.          yet.  So, for now, we just assume that stack slots never exist
  2908.          in this case.  */
  2909.       || REG_PARM_STACK_SPACE (fndecl) > 0
  2910. #endif
  2911.       )
  2912.     {
  2913.       stack_args_size.constant += arg_size.constant;
  2914.       if (arg_size.var)
  2915.         ADD_PARM_SIZE (stack_args_size, arg_size.var);
  2916.     }
  2917.       else
  2918.     /* No stack slot was pushed for this parm.  */
  2919.     stack_parm = 0;
  2920.  
  2921.       /* Update info on where next arg arrives in registers.  */
  2922.  
  2923.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
  2924.                 passed_type, ! last_named);
  2925.  
  2926.       /* If this is our second time through, we are done with this parm. */
  2927.       if (second_time)
  2928.     continue;
  2929.  
  2930.       /* If we can't trust the parm stack slot to be aligned enough
  2931.      for its ultimate type, don't use that slot after entry.
  2932.      We'll make another stack slot, if we need one.  */
  2933.       {
  2934. #ifdef FUNCTION_ARG_BOUNDARY
  2935.     int thisparm_boundary
  2936.       = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
  2937. #else
  2938.     int thisparm_boundary = PARM_BOUNDARY;
  2939. #endif
  2940.  
  2941.     if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
  2942.       stack_parm = 0;
  2943.       }
  2944.  
  2945.       /* Now adjust STACK_PARM to the mode and precise location
  2946.      where this parameter should live during execution,
  2947.      if we discover that it must live in the stack during execution.
  2948.      To make debuggers happier on big-endian machines, we store
  2949.      the value in the last bytes of the space available.  */
  2950.  
  2951.       if (nominal_mode != BLKmode && nominal_mode != passed_mode
  2952.       && stack_parm != 0)
  2953.     {
  2954.       rtx offset_rtx;
  2955.  
  2956. #if BYTES_BIG_ENDIAN
  2957.       if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
  2958.         stack_offset.constant += (GET_MODE_SIZE (passed_mode)
  2959.                       - GET_MODE_SIZE (nominal_mode));
  2960. #endif
  2961.  
  2962.       offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2963.       if (offset_rtx == const0_rtx)
  2964.         stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
  2965.       else
  2966.         stack_parm = gen_rtx (MEM, nominal_mode,
  2967.                   gen_rtx (PLUS, DPmode,
  2968.                        internal_arg_pointer, offset_rtx));
  2969.  
  2970.       /* If this is a memory ref that contains aggregate components,
  2971.          mark it as such for cse and loop optimize.  */
  2972.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  2973.     }
  2974.  
  2975.       /* ENTRY_PARM is an RTX for the parameter as it arrives,
  2976.      in the mode in which it arrives.
  2977.      STACK_PARM is an RTX for a stack slot where the parameter can live
  2978.      during the function (in case we want to put it there).
  2979.      STACK_PARM is 0 if no stack slot was pushed for it.
  2980.  
  2981.      Now output code if necessary to convert ENTRY_PARM to
  2982.      the type in which this function declares it,
  2983.      and store that result in an appropriate place,
  2984.      which may be a pseudo reg, may be STACK_PARM,
  2985.      or may be a local stack slot if STACK_PARM is 0.
  2986.  
  2987.      Set DECL_RTL to that place.  */
  2988.  
  2989.       if (nominal_mode == BLKmode)
  2990.     {
  2991.       /* If a BLKmode arrives in registers, copy it to a stack slot.  */
  2992.       if (GET_CODE (entry_parm) == REG)
  2993.         {
  2994.           int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
  2995.                         UNITS_PER_WORD);
  2996.  
  2997.           /* Note that we will be storing an integral number of words.
  2998.          So we have to be careful to ensure that we allocate an
  2999.          integral number of words.  We do this below in the
  3000.          assign_stack_local if space was not allocated in the argument
  3001.          list.  If it was, this will not work if PARM_BOUNDARY is not
  3002.          a multiple of BITS_PER_WORD.  It isn't clear how to fix this
  3003.          if it becomes a problem.  */
  3004.  
  3005.           if (stack_parm == 0)
  3006.         {
  3007.           stack_parm
  3008.             = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
  3009.           /* If this is a memory ref that contains aggregate components,
  3010.              mark it as such for cse and loop optimize.  */
  3011.           MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3012.         }
  3013.  
  3014.           else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
  3015.         abort ();
  3016.  
  3017.           move_block_from_reg (REGNO (entry_parm),
  3018.                    validize_mem (stack_parm),
  3019.                    size_stored / UNITS_PER_WORD);
  3020.         }
  3021.       DECL_RTL (parm) = stack_parm;
  3022.     }
  3023.       else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
  3024.            && ! DECL_INLINE (fndecl))
  3025.           /* layout_decl may set this.  */
  3026.           || TREE_ADDRESSABLE (parm)
  3027.           || TREE_SIDE_EFFECTS (parm)
  3028.           /* If -ffloat-store specified, don't put explicit
  3029.              float variables into registers.  */
  3030.           || (flag_float_store
  3031.               && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
  3032.            /* Always assign pseudo to structure return or item passed
  3033.           by invisible reference.  */
  3034.            || passed_pointer || parm == function_result_decl)
  3035.     {
  3036.       /* Store the parm in a pseudoregister during the function, but we
  3037.          may need to do it in a wider mode.  */
  3038.  
  3039.       register rtx parmreg;
  3040.  
  3041.       unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
  3042.       if (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
  3043.           || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE
  3044.           || TREE_CODE (TREE_TYPE (parm)) == BOOLEAN_TYPE
  3045.           || TREE_CODE (TREE_TYPE (parm)) == CHAR_TYPE
  3046.           || TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE
  3047.           || TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE
  3048.           || TREE_CODE (TREE_TYPE (parm)) == OFFSET_TYPE)
  3049.         {
  3050.           PROMOTE_MODE (nominal_mode, unsignedp, TREE_TYPE (parm));
  3051.         }
  3052.  
  3053.       parmreg = gen_reg_rtx (nominal_mode);
  3054.       REG_USERVAR_P (parmreg) = 1;
  3055.  
  3056.       /* If this was an item that we received a pointer to, set DECL_RTL
  3057.          appropriately.  */
  3058.       if (passed_pointer)
  3059.         {
  3060.           DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
  3061.           MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
  3062.         }
  3063.       else
  3064.         DECL_RTL (parm) = parmreg;
  3065.  
  3066.       /* Copy the value into the register.  */
  3067.       if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  3068.         {
  3069.           /* If ENTRY_PARM is a hard register, it might be in a register
  3070.          not valid for operating in its mode (e.g., an odd-numbered
  3071.          register for a DFmode).  In that case, moves are the only
  3072.          thing valid, so we can't do a convert from there.  This
  3073.          occurs when the calling sequence allow such misaligned
  3074.          usages.  */
  3075.           if (GET_CODE (entry_parm) == REG
  3076.           && REGNO (entry_parm) < FIRST_PSEUDO_REGISTER
  3077.           && ! HARD_REGNO_MODE_OK (REGNO (entry_parm),
  3078.                        GET_MODE (entry_parm)))
  3079.         convert_move (parmreg, copy_to_reg (entry_parm), unsignedp);
  3080.           else
  3081.         convert_move (parmreg, validize_mem (entry_parm), unsignedp);
  3082.         }
  3083.       else
  3084.         emit_move_insn (parmreg, validize_mem (entry_parm));
  3085.  
  3086.       /* If we were passed a pointer but the actual value
  3087.          can safely live in a register, put it in one.  */
  3088.       if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
  3089.           && ! ((obey_regdecls && ! DECL_REGISTER (parm)
  3090.              && ! DECL_INLINE (fndecl))
  3091.             /* layout_decl may set this.  */
  3092.             || TREE_ADDRESSABLE (parm)
  3093.             || TREE_SIDE_EFFECTS (parm)
  3094.             /* If -ffloat-store specified, don't put explicit
  3095.                float variables into registers.  */
  3096.             || (flag_float_store
  3097.             && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
  3098.         {
  3099.           /* We can't use nominal_mode, because it will have been set to
  3100.          Pmode above.  We must use the actual mode of the parm.  */
  3101.           parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
  3102.           emit_move_insn (parmreg, DECL_RTL (parm));
  3103.           DECL_RTL (parm) = parmreg;
  3104.         }
  3105.  
  3106.       /* In any case, record the parm's desired stack location
  3107.          in case we later discover it must live in the stack.  */
  3108.       if (REGNO (parmreg) >= nparmregs)
  3109.         {
  3110.           rtx *new;
  3111.           nparmregs = REGNO (parmreg) + 5;
  3112.           new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  3113.           bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx));
  3114.           parm_reg_stack_loc = new;
  3115.         }
  3116.       parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  3117.  
  3118.       /* Mark the register as eliminable if we did no conversion
  3119.          and it was copied from memory at a fixed offset,
  3120.          and the arg pointer was not copied to a pseudo-reg.
  3121.          If the arg pointer is a pseudo reg or the offset formed
  3122.          an invalid address, such memory-equivalences
  3123.          as we make here would screw up life analysis for it.  */
  3124.       if (nominal_mode == passed_mode
  3125.           && GET_CODE (entry_parm) == MEM
  3126.           && entry_parm == stack_parm
  3127.           && stack_offset.var == 0
  3128.           && reg_mentioned_p (virtual_incoming_args_rtx,
  3129.                   XEXP (entry_parm, 0)))
  3130.         REG_NOTES (get_last_insn ())
  3131.           = gen_rtx (EXPR_LIST, REG_EQUIV,
  3132.              entry_parm, REG_NOTES (get_last_insn ()));
  3133.  
  3134.       /* For pointer data type, suggest pointer register.  */
  3135.       if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  3136.         mark_reg_pointer (parmreg);
  3137.     }
  3138.       else
  3139.     {
  3140.       /* Value must be stored in the stack slot STACK_PARM
  3141.          during function execution.  */
  3142.  
  3143.       if (passed_mode != nominal_mode)
  3144.         {
  3145.           /* Conversion is required.   */
  3146.           if (GET_CODE (entry_parm) == REG
  3147.           && REGNO (entry_parm) < FIRST_PSEUDO_REGISTER
  3148.           && ! HARD_REGNO_MODE_OK (REGNO (entry_parm), passed_mode))
  3149.         entry_parm = copy_to_reg (entry_parm);
  3150.  
  3151.           entry_parm = convert_to_mode (nominal_mode, entry_parm,
  3152.                         TREE_UNSIGNED (TREE_TYPE (parm)));
  3153.         }
  3154.  
  3155.       if (entry_parm != stack_parm)
  3156.         {
  3157.           if (stack_parm == 0)
  3158.         {
  3159.           stack_parm
  3160.             = assign_stack_local (GET_MODE (entry_parm),
  3161.                       GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
  3162.           /* If this is a memory ref that contains aggregate components,
  3163.              mark it as such for cse and loop optimize.  */
  3164.           MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3165.         }
  3166.  
  3167.           emit_move_insn (validize_mem (stack_parm),
  3168.                   validize_mem (entry_parm));
  3169.         }
  3170.  
  3171.       DECL_RTL (parm) = stack_parm;
  3172.     }
  3173.       
  3174.       /* If this "parameter" was the place where we are receiving the
  3175.      function's incoming structure pointer, set up the result.  */
  3176.       if (parm == function_result_decl)
  3177.     DECL_RTL (DECL_RESULT (fndecl))
  3178.       = gen_rtx (MEM, DECL_MODE (DECL_RESULT (fndecl)), DECL_RTL (parm));
  3179.  
  3180.       if (TREE_THIS_VOLATILE (parm))
  3181.     MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
  3182.       if (TREE_READONLY (parm))
  3183.     RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
  3184.     }
  3185.  
  3186.   /* Re-reverse the order of arguments if this is a Pascal function. */
  3187.   if (current_function_is_pascal)
  3188.     fnargs = DECL_ARGUMENTS (fndecl) = nreverse (DECL_ARGUMENTS (fndecl));
  3189.  
  3190.   max_parm_reg = max_reg_num ();
  3191.   last_parm_insn = get_last_insn ();
  3192.  
  3193.   current_function_args_size = stack_args_size.constant;
  3194.  
  3195.   /* Adjust function incoming argument size for alignment and
  3196.      minimum length.  */
  3197.  
  3198. #ifdef REG_PARM_STACK_SPACE
  3199. #ifndef MAYBE_REG_PARM_STACK_SPACE
  3200.   current_function_args_size = MAX (current_function_args_size,
  3201.                     REG_PARM_STACK_SPACE (fndecl));
  3202. #endif
  3203. #endif
  3204.  
  3205. #ifdef STACK_BOUNDARY
  3206. #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
  3207.  
  3208.   current_function_args_size
  3209.     = ((current_function_args_size + STACK_BYTES - 1)
  3210.        / STACK_BYTES) * STACK_BYTES;
  3211. #endif  
  3212.  
  3213. #ifdef ARGS_GROW_DOWNWARD
  3214.   current_function_arg_offset_rtx
  3215.     = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
  3216.        : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,    
  3217.                   size_int (-stack_args_size.constant)),   
  3218.               NULL_RTX, VOIDmode, 0));
  3219. #else
  3220.   current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
  3221. #endif
  3222.  
  3223.   /* See how many bytes, if any, of its args a function should try to pop
  3224.      on return.  */
  3225.  
  3226.   current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
  3227.                          current_function_args_size);
  3228.  
  3229.   /* For stdarg.h function, save info about regs and stack space
  3230.      used by the named args.  */
  3231.  
  3232.   if (stdarg)
  3233.     current_function_args_info = args_so_far;
  3234.  
  3235.   /* Set the rtx used for the function return value.  Put this in its
  3236.      own variable so any optimizers that need this information don't have
  3237.      to include tree.h.  Do this here so it gets done when an inlined
  3238.      function gets output.  */
  3239.  
  3240.   current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
  3241. }
  3242.  
  3243. /* Compute the size and offset from the start of the stacked arguments for a
  3244.    parm passed in mode PASSED_MODE and with type TYPE.
  3245.  
  3246.    INITIAL_OFFSET_PTR points to the current offset into the stacked
  3247.    arguments.
  3248.  
  3249.    The starting offset and size for this parm are returned in *OFFSET_PTR
  3250.    and *ARG_SIZE_PTR, respectively.
  3251.  
  3252.    IN_REGS is non-zero if the argument will be passed in registers.  It will
  3253.    never be set if REG_PARM_STACK_SPACE is not defined.
  3254.  
  3255.    FNDECL is the function in which the argument was defined.
  3256.  
  3257.    There are two types of rounding that are done.  The first, controlled by
  3258.    FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
  3259.    list to be aligned to the specific boundary (in bits).  This rounding
  3260.    affects the initial and starting offsets, but not the argument size.
  3261.  
  3262.    The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
  3263.    optionally rounds the size of the parm to PARM_BOUNDARY.  The
  3264.    initial offset is not affected by this rounding, while the size always
  3265.    is and the starting offset may be.  */
  3266.  
  3267. /*  offset_ptr will be negative for ARGS_GROW_DOWNWARD case; 
  3268.     initial_offset_ptr is positive because locate_and_pad_parm's
  3269.     callers pass in the total size of args so far as
  3270.     initial_offset_ptr. arg_size_ptr is always positive.*/
  3271.  
  3272. static void pad_to_arg_alignment (), pad_below ();
  3273.  
  3274. void
  3275. locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
  3276.              initial_offset_ptr, offset_ptr, arg_size_ptr)
  3277.      enum machine_mode passed_mode;
  3278.      tree type;
  3279.      int in_regs;
  3280.      tree fndecl;
  3281.      struct args_size *initial_offset_ptr;
  3282.      struct args_size *offset_ptr;
  3283.      struct args_size *arg_size_ptr;
  3284. {
  3285.   tree sizetree
  3286.     = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
  3287.   enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
  3288.   int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
  3289.   int boundary_in_bytes = boundary / BITS_PER_UNIT;
  3290.   int reg_parm_stack_space = 0;
  3291.  
  3292. #ifdef REG_PARM_STACK_SPACE
  3293.   /* If we have found a stack parm before we reach the end of the
  3294.      area reserved for registers, skip that area.  */
  3295.   if (! in_regs)
  3296.     {
  3297. #ifdef MAYBE_REG_PARM_STACK_SPACE
  3298.       reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
  3299. #else
  3300.       reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
  3301. #endif
  3302.       if (reg_parm_stack_space > 0)
  3303.     {
  3304.       if (initial_offset_ptr->var)
  3305.         {
  3306.           initial_offset_ptr->var
  3307.         = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
  3308.                   size_int (reg_parm_stack_space));
  3309.           initial_offset_ptr->constant = 0;
  3310.         }
  3311.       else if (initial_offset_ptr->constant < reg_parm_stack_space)
  3312.         initial_offset_ptr->constant = reg_parm_stack_space;
  3313.     }
  3314.     }
  3315. #endif /* REG_PARM_STACK_SPACE */
  3316.  
  3317.   arg_size_ptr->var = 0;
  3318.   arg_size_ptr->constant = 0;
  3319.  
  3320. #ifdef ARGS_GROW_DOWNWARD
  3321.   if (initial_offset_ptr->var)
  3322.     {
  3323.       offset_ptr->constant = 0;
  3324.       offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
  3325.                     initial_offset_ptr->var);
  3326.     }
  3327.   else
  3328.     {
  3329.       offset_ptr->constant = - initial_offset_ptr->constant;
  3330.       offset_ptr->var = 0;
  3331.     }
  3332.   if (where_pad == upward
  3333.       && (TREE_CODE (sizetree) != INTEGER_CST
  3334.       || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
  3335.     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  3336.   SUB_PARM_SIZE (*offset_ptr, sizetree);
  3337.   if (where_pad != downward)
  3338.     pad_to_arg_alignment (offset_ptr, boundary);
  3339.   if (initial_offset_ptr->var)
  3340.     {
  3341.       arg_size_ptr->var = size_binop (MINUS_EXPR,
  3342.                       size_binop (MINUS_EXPR,
  3343.                           integer_zero_node,
  3344.                           initial_offset_ptr->var),
  3345.                       offset_ptr->var);
  3346.     }
  3347.   else
  3348.     {
  3349.       arg_size_ptr->constant = (- initial_offset_ptr->constant -
  3350.                 offset_ptr->constant); 
  3351.     }
  3352. /*  ADD_PARM_SIZE (*arg_size_ptr, sizetree); */
  3353.   if (where_pad == downward)
  3354.     pad_below (arg_size_ptr, passed_mode, sizetree);
  3355. #else /* !ARGS_GROW_DOWNWARD */
  3356.   pad_to_arg_alignment (initial_offset_ptr, boundary);
  3357.   *offset_ptr = *initial_offset_ptr;
  3358.   if (where_pad == downward)
  3359.     pad_below (offset_ptr, passed_mode, sizetree);
  3360.  
  3361. #ifdef PUSH_ROUNDING
  3362.   if (passed_mode != BLKmode)
  3363.     sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
  3364. #endif
  3365.  
  3366.   if (where_pad != none
  3367.       && (TREE_CODE (sizetree) != INTEGER_CST
  3368.       || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
  3369.     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  3370.  
  3371.   ADD_PARM_SIZE (*arg_size_ptr, sizetree);
  3372. #endif /* ARGS_GROW_DOWNWARD */
  3373. }
  3374.  
  3375. /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
  3376.    BOUNDARY is measured in bits, but must be a multiple of a storage unit.  */
  3377.  
  3378. static void
  3379. pad_to_arg_alignment (offset_ptr, boundary)
  3380.      struct args_size *offset_ptr;
  3381.      int boundary;
  3382. {
  3383.   int boundary_in_bytes = boundary / BITS_PER_UNIT;
  3384.   
  3385.   if (boundary > BITS_PER_UNIT)
  3386.     {
  3387.       if (offset_ptr->var)
  3388.     {
  3389.       offset_ptr->var  =
  3390. #ifdef ARGS_GROW_DOWNWARD
  3391.         round_down 
  3392. #else
  3393.         round_up
  3394. #endif
  3395.           (ARGS_SIZE_TREE (*offset_ptr),
  3396.            boundary / BITS_PER_UNIT);
  3397.       offset_ptr->constant = 0; /*?*/
  3398.     }
  3399.       else
  3400.     offset_ptr->constant =
  3401. #ifdef ARGS_GROW_DOWNWARD
  3402.       FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
  3403. #else
  3404.       CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
  3405. #endif
  3406.     }
  3407. }
  3408.  
  3409. static void
  3410. pad_below (offset_ptr, passed_mode, sizetree)
  3411.      struct args_size *offset_ptr;
  3412.      enum machine_mode passed_mode;
  3413.      tree sizetree;
  3414. {
  3415.   if (passed_mode != BLKmode)
  3416.     {
  3417.       if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  3418.     offset_ptr->constant
  3419.       += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  3420.            / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  3421.           - GET_MODE_SIZE (passed_mode));
  3422.     }
  3423.   else
  3424.     {
  3425.       if (TREE_CODE (sizetree) != INTEGER_CST
  3426.       || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
  3427.     {
  3428.       /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  3429.       tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  3430.       /* Add it in.  */
  3431.       ADD_PARM_SIZE (*offset_ptr, s2);
  3432.       SUB_PARM_SIZE (*offset_ptr, sizetree);
  3433.     }
  3434.     }
  3435. }
  3436.  
  3437. static tree
  3438. round_down (value, divisor)
  3439.      tree value;
  3440.      int divisor;
  3441. {
  3442.   return size_binop (MULT_EXPR,
  3443.              size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
  3444.              size_int (divisor));
  3445. }
  3446.  
  3447. /* Walk the tree of blocks describing the binding levels within a function
  3448.    and warn about uninitialized variables.
  3449.    This is done after calling flow_analysis and before global_alloc
  3450.    clobbers the pseudo-regs to hard regs.  */
  3451.  
  3452. void
  3453. uninitialized_vars_warning (block)
  3454.      tree block;
  3455. {
  3456.   register tree decl, sub;
  3457.   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
  3458.     {
  3459.       if (TREE_CODE (decl) == VAR_DECL
  3460.       /* These warnings are unreliable for and aggregates
  3461.          because assigning the fields one by one can fail to convince
  3462.          flow.c that the entire aggregate was initialized.
  3463.          Unions are troublesome because members may be shorter.  */
  3464.       && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
  3465.       && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
  3466.       && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
  3467.       && DECL_RTL (decl) != 0
  3468.       && GET_CODE (DECL_RTL (decl)) == REG
  3469.       && regno_uninitialized (REGNO (DECL_RTL (decl))))
  3470.     warning_with_decl (decl,
  3471.                "`%s' may be used uninitialized in this function");
  3472.       if (TREE_CODE (decl) == VAR_DECL
  3473.       && DECL_RTL (decl) != 0
  3474.       && GET_CODE (DECL_RTL (decl)) == REG
  3475.       && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  3476.     warning_with_decl (decl,
  3477.                "variable `%s' may be clobbered by `longjmp'");
  3478.     }
  3479.   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  3480.     uninitialized_vars_warning (sub);
  3481. }
  3482.  
  3483. /* Do the appropriate part of uninitialized_vars_warning
  3484.    but for arguments instead of local variables.  */
  3485.  
  3486. void
  3487. setjmp_args_warning (block)
  3488.      tree block;
  3489. {
  3490.   register tree decl;
  3491.   for (decl = DECL_ARGUMENTS (current_function_decl);
  3492.        decl; decl = TREE_CHAIN (decl))
  3493.     if (DECL_RTL (decl) != 0
  3494.     && GET_CODE (DECL_RTL (decl)) == REG
  3495.     && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  3496.       warning_with_decl (decl, "argument `%s' may be clobbered by `longjmp'");
  3497. }
  3498.  
  3499. /* If this function call setjmp, put all vars into the stack
  3500.    unless they were declared `register'.  */
  3501.  
  3502. void
  3503. setjmp_protect (block)
  3504.      tree block;
  3505. {
  3506.   register tree decl, sub;
  3507.   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
  3508.     if ((TREE_CODE (decl) == VAR_DECL
  3509.      || TREE_CODE (decl) == PARM_DECL)
  3510.     && DECL_RTL (decl) != 0
  3511.     && GET_CODE (DECL_RTL (decl)) == REG
  3512.     /* If this variable came from an inline function, it must be
  3513.        that it's life doesn't overlap the setjmp.  If there was a
  3514.        setjmp in the function, it would already be in memory.  We
  3515.        must exclude such variable because their DECL_RTL might be
  3516.        set to strange things such as virtual_stack_vars_rtx.  */
  3517.     && ! DECL_FROM_INLINE (decl)
  3518.     && (
  3519. #ifdef NON_SAVING_SETJMP
  3520.         /* If longjmp doesn't restore the registers,
  3521.            don't put anything in them.  */
  3522.         NON_SAVING_SETJMP
  3523.         ||
  3524. #endif
  3525.         ! DECL_REGISTER (decl)))
  3526.       put_var_into_stack (decl);
  3527.   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  3528.     setjmp_protect (sub);
  3529. }
  3530.  
  3531. /* Like the previous function, but for args instead of local variables.  */
  3532.  
  3533. void
  3534. setjmp_protect_args ()
  3535. {
  3536.   register tree decl, sub;
  3537.   for (decl = DECL_ARGUMENTS (current_function_decl);
  3538.        decl; decl = TREE_CHAIN (decl))
  3539.     if ((TREE_CODE (decl) == VAR_DECL
  3540.      || TREE_CODE (decl) == PARM_DECL)
  3541.     && DECL_RTL (decl) != 0
  3542.     && GET_CODE (DECL_RTL (decl)) == REG
  3543.     && (
  3544.         /* If longjmp doesn't restore the registers,
  3545.            don't put anything in them.  */
  3546. #ifdef NON_SAVING_SETJMP
  3547.         NON_SAVING_SETJMP
  3548.         ||
  3549. #endif
  3550.         ! DECL_REGISTER (decl)))
  3551.       put_var_into_stack (decl);
  3552. }
  3553.  
  3554. /* Return the context-pointer register corresponding to DECL,
  3555.    or 0 if it does not need one.  */
  3556.  
  3557. rtx
  3558. lookup_static_chain (decl)
  3559.      tree decl;
  3560. {
  3561.   tree context = decl_function_context (decl);
  3562.   tree link;
  3563.  
  3564.   if (context == 0)
  3565.     return 0;
  3566.   
  3567.   /* We treat inline_function_decl as an alias for the current function
  3568.      because that is the inline function whose vars, types, etc.
  3569.      are being merged into the current function.
  3570.      See expand_inline_function.  */
  3571.   if (context == current_function_decl || context == inline_function_decl)
  3572.     return virtual_stack_vars_rtx;
  3573.  
  3574.   for (link = context_display; link; link = TREE_CHAIN (link))
  3575.     if (TREE_PURPOSE (link) == context)
  3576.       return RTL_EXPR_RTL (TREE_VALUE (link));
  3577.  
  3578.   abort ();
  3579. }
  3580.  
  3581. /* Convert a stack slot address ADDR for variable VAR
  3582.    (from a containing function)
  3583.    into an address valid in this function (using a static chain).  */
  3584.  
  3585. rtx
  3586. fix_lexical_addr (addr, var)
  3587.      rtx addr;
  3588.      tree var;
  3589. {
  3590.   rtx basereg;
  3591.   int displacement;
  3592.   tree context = decl_function_context (var);
  3593.   struct function *fp;
  3594.   rtx base = 0;
  3595.  
  3596.   /* If this is the present function, we need not do anything.  */
  3597.   if (context == current_function_decl || context == inline_function_decl)
  3598.     return addr;
  3599.  
  3600.   for (fp = outer_function_chain; fp; fp = fp->next)
  3601.     if (fp->decl == context)
  3602.       break;
  3603.  
  3604.   if (fp == 0)
  3605.     abort ();
  3606.  
  3607.   /* Decode given address as base reg plus displacement.  */
  3608.   if (GET_CODE (addr) == REG)
  3609.     basereg = addr, displacement = 0;
  3610.   else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
  3611.     basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
  3612.   else
  3613.     abort ();
  3614.  
  3615.   /* We accept vars reached via the containing function's
  3616.      incoming arg pointer and via its stack variables pointer.  */
  3617.   if (basereg == fp->internal_arg_pointer)
  3618.     {
  3619.       /* If reached via arg pointer, get the arg pointer value
  3620.      out of that function's stack frame.
  3621.  
  3622.      There are two cases:  If a separate ap is needed, allocate a
  3623.      slot in the outer function for it and dereference it that way.
  3624.      This is correct even if the real ap is actually a pseudo.
  3625.      Otherwise, just adjust the offset from the frame pointer to
  3626.      compensate.  */
  3627.  
  3628. #ifdef NEED_SEPARATE_AP
  3629.       rtx addr;
  3630.  
  3631.       if (fp->arg_pointer_save_area == 0)
  3632.     fp->arg_pointer_save_area
  3633.       = assign_outer_stack_local (DPmode, GET_MODE_SIZE (Pmode), 0, fp);
  3634.  
  3635.       addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
  3636.       addr = memory_address (DPmode, addr);
  3637.  
  3638.       base = copy_to_reg (gen_rtx (MEM, DPmode, addr));
  3639. #else
  3640.       displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
  3641.       base = lookup_static_chain (var);
  3642. #endif
  3643.     }
  3644.  
  3645.   else if (basereg == virtual_stack_vars_rtx)
  3646.     {
  3647.       /* This is the same code as lookup_static_chain, duplicated here to
  3648.      avoid an extra call to decl_function_context.  */
  3649.       tree link;
  3650.  
  3651.       for (link = context_display; link; link = TREE_CHAIN (link))
  3652.     if (TREE_PURPOSE (link) == context)
  3653.       {
  3654.         base = RTL_EXPR_RTL (TREE_VALUE (link));
  3655.         break;
  3656.       }
  3657.     }
  3658.  
  3659.   if (base == 0)
  3660.     abort ();
  3661.  
  3662.   /* Use same offset, relative to appropriate static chain or argument
  3663.      pointer.  */
  3664.   return plus_constant (base, displacement);
  3665. }
  3666.  
  3667. /* Return the address of the trampoline for entering nested fn FUNCTION.
  3668.    If necessary, allocate a trampoline (in the stack frame)
  3669.    and emit rtl to initialize its contents (at entry to this function).  */
  3670.  
  3671. rtx
  3672. trampoline_address (function)
  3673.      tree function;
  3674. {
  3675.   tree link;
  3676.   tree rtlexp;
  3677.   rtx tramp;
  3678.   struct function *fp;
  3679.   tree fn_context;
  3680.  
  3681.   /* Find an existing trampoline and return it.  */
  3682.   for (link = trampoline_list; link; link = TREE_CHAIN (link))
  3683.     if (TREE_PURPOSE (link) == function)
  3684.       return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0);
  3685.   for (fp = outer_function_chain; fp; fp = fp->next)
  3686.     for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
  3687.       if (TREE_PURPOSE (link) == function)
  3688.     {
  3689.       tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
  3690.                     function);
  3691.       return round_trampoline_addr (tramp);
  3692.     }
  3693.  
  3694.   /* None exists; we must make one.  */
  3695.  
  3696.   /* Find the `struct function' for the function containing FUNCTION.  */
  3697.   fp = 0;
  3698.   fn_context = decl_function_context (function);
  3699.   if (fn_context != current_function_decl)
  3700.     for (fp = outer_function_chain; fp; fp = fp->next)
  3701.       if (fp->decl == fn_context)
  3702.     break;
  3703.  
  3704.   /* Allocate run-time space for this trampoline
  3705.      (usually in the defining function's stack frame).  */
  3706. #ifdef ALLOCATE_TRAMPOLINE
  3707.   tramp = ALLOCATE_TRAMPOLINE (fp);
  3708. #else
  3709.   /* If rounding needed, allocate extra space
  3710.      to ensure we have TRAMPOLINE_SIZE bytes left after rounding up.  */
  3711. #ifdef TRAMPOLINE_ALIGNMENT
  3712. #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
  3713. #else
  3714. #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
  3715. #endif
  3716.   if (fp != 0)
  3717.     tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
  3718.   else
  3719.     tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
  3720. #endif
  3721.  
  3722.   /* Record the trampoline for reuse and note it for later initialization
  3723.      by expand_function_end.  */
  3724.   if (fp != 0)
  3725.     {
  3726.       push_obstacks (fp->current_obstack, fp->function_maybepermanent_obstack);
  3727.       rtlexp = make_node (RTL_EXPR);
  3728.       RTL_EXPR_RTL (rtlexp) = tramp;
  3729.       fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
  3730.       pop_obstacks ();
  3731.     }
  3732.   else
  3733.     {
  3734.       /* Make the RTL_EXPR node temporary, not momentary, so that the
  3735.      trampoline_list doesn't become garbage.  */
  3736.       int momentary = suspend_momentary ();
  3737.       rtlexp = make_node (RTL_EXPR);
  3738.       resume_momentary (momentary);
  3739.  
  3740.       RTL_EXPR_RTL (rtlexp) = tramp;
  3741.       trampoline_list = tree_cons (function, rtlexp, trampoline_list);
  3742.     }
  3743.  
  3744.   tramp = fix_lexical_addr (XEXP (tramp, 0), function);
  3745.   return round_trampoline_addr (tramp);
  3746. }
  3747.  
  3748. /* Given a trampoline address,
  3749.    round it to multiple of TRAMPOLINE_ALIGNMENT.  */
  3750.  
  3751. static rtx
  3752. round_trampoline_addr (tramp)
  3753.      rtx tramp;
  3754. {
  3755. #ifdef TRAMPOLINE_ALIGNMENT
  3756.   /* Round address up to desired boundary.  */
  3757. #if defined(APPLE_HAX) && defined(PTR_HACK)
  3758.   rtx temp = gen_reg_rtx (TPmode);
  3759.   temp = expand_binop (TPmode, add_optab, tramp,
  3760.                gen_rtx (CONST_INT, VOIDmode, TRAMPOLINE_ALIGNMENT - 1),
  3761.                temp, 0, OPTAB_LIB_WIDEN);
  3762.   tramp = expand_binop (TPmode, and_optab, temp,
  3763.             gen_rtx (CONST_INT, VOIDmode, - TRAMPOLINE_ALIGNMENT),
  3764.             temp, 0, OPTAB_LIB_WIDEN);
  3765. #else
  3766.   rtx temp = gen_reg_rtx (Pmode);
  3767.   temp = expand_binop (Pmode, add_optab, tramp,
  3768.                GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
  3769.                temp, 0, OPTAB_LIB_WIDEN);
  3770.   tramp = expand_binop (Pmode, and_optab, temp,
  3771.             GEN_INT (- TRAMPOLINE_ALIGNMENT),
  3772.             temp, 0, OPTAB_LIB_WIDEN);
  3773. #endif
  3774. #endif
  3775.   return tramp;
  3776. }
  3777.  
  3778. /* The functions identify_blocks and reorder_blocks provide a way to
  3779.    reorder the tree of BLOCK nodes, for optimizers that reshuffle or
  3780.    duplicate portions of the RTL code.  Call identify_blocks before
  3781.    changing the RTL, and call reorder_blocks after.  */
  3782.  
  3783. static int all_blocks ();
  3784. static tree blocks_nreverse ();
  3785.  
  3786. /* Put all this function's BLOCK nodes into a vector, and return it.
  3787.    Also store in each NOTE for the beginning or end of a block
  3788.    the index of that block in the vector.
  3789.    The arguments are TOP_BLOCK, the top-level block of the function,
  3790.    and INSNS, the insn chain of the function.  */
  3791.  
  3792. tree *
  3793. identify_blocks (top_block, insns)
  3794.      tree top_block;
  3795.      rtx insns;
  3796. {
  3797.   int n_blocks;
  3798.   tree *block_vector;
  3799.   int *block_stack;
  3800.   int depth = 0;
  3801.   int next_block_number = 0;
  3802.   int current_block_number = 0;
  3803.   rtx insn;
  3804.  
  3805.   if (top_block == 0)
  3806.     return 0;
  3807.  
  3808.   n_blocks = all_blocks (top_block, 0);
  3809.   block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
  3810.   block_stack = (int *) alloca (n_blocks * sizeof (int));
  3811.  
  3812.   all_blocks (top_block, block_vector);
  3813.  
  3814.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  3815.     if (GET_CODE (insn) == NOTE)
  3816.       {
  3817.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  3818.       {
  3819.         block_stack[depth++] = current_block_number;
  3820.         current_block_number = next_block_number;
  3821.         NOTE_BLOCK_NUMBER (insn) =  next_block_number++;
  3822.       }
  3823.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  3824.       {
  3825.         current_block_number = block_stack[--depth];
  3826.         NOTE_BLOCK_NUMBER (insn) = current_block_number;
  3827.       }
  3828.       }
  3829.  
  3830.   return block_vector;
  3831. }
  3832.  
  3833. /* Given BLOCK_VECTOR which was returned by identify_blocks,
  3834.    and a revised instruction chain, rebuild the tree structure
  3835.    of BLOCK nodes to correspond to the new order of RTL.
  3836.    The new block tree is inserted below TOP_BLOCK.
  3837.    Returns the current top-level block.  */
  3838.  
  3839. tree
  3840. reorder_blocks (block_vector, top_block, insns)
  3841.      tree *block_vector;
  3842.      tree top_block;
  3843.      rtx insns;
  3844. {
  3845.   tree current_block = top_block;
  3846.   rtx insn;
  3847.  
  3848.   if (block_vector == 0)
  3849.     return top_block;
  3850.  
  3851.   /* Prune the old tree away, so that it doesn't get in the way.  */
  3852.   BLOCK_SUBBLOCKS (current_block) = 0;
  3853.  
  3854.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  3855.     if (GET_CODE (insn) == NOTE)
  3856.       {
  3857.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  3858.       {
  3859.         tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
  3860.         /* If we have seen this block before, copy it.  */
  3861.         if (TREE_ASM_WRITTEN (block))
  3862.           block = copy_node (block);
  3863.         BLOCK_SUBBLOCKS (block) = 0;
  3864.         TREE_ASM_WRITTEN (block) = 1;
  3865.         BLOCK_SUPERCONTEXT (block) = current_block; 
  3866.         BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
  3867.         BLOCK_SUBBLOCKS (current_block) = block;
  3868.         current_block = block;
  3869.         NOTE_SOURCE_FILE (insn) = 0;
  3870.       }
  3871.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  3872.       {
  3873.         BLOCK_SUBBLOCKS (current_block)
  3874.           = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
  3875.         current_block = BLOCK_SUPERCONTEXT (current_block);
  3876.         NOTE_SOURCE_FILE (insn) = 0;
  3877.       }
  3878.       }
  3879.  
  3880.   return current_block;
  3881. }
  3882.  
  3883. /* Reverse the order of elements in the chain T of blocks,
  3884.    and return the new head of the chain (old last element).  */
  3885.  
  3886. static tree
  3887. blocks_nreverse (t)
  3888.      tree t;
  3889. {
  3890.   register tree prev = 0, decl, next;
  3891.   for (decl = t; decl; decl = next)
  3892.     {
  3893.       next = BLOCK_CHAIN (decl);
  3894.       BLOCK_CHAIN (decl) = prev;
  3895.       prev = decl;
  3896.     }
  3897.   return prev;
  3898. }
  3899.  
  3900. /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
  3901.    Also clear TREE_ASM_WRITTEN in all blocks.  */
  3902.  
  3903. static int
  3904. all_blocks (block, vector)
  3905.      tree block;
  3906.      tree *vector;
  3907. {
  3908.   int n_blocks = 1;
  3909.   tree subblocks; 
  3910.  
  3911.   TREE_ASM_WRITTEN (block) = 0;
  3912.   /* Record this block.  */
  3913.   if (vector)
  3914.     vector[0] = block;
  3915.  
  3916.   /* Record the subblocks, and their subblocks.  */
  3917.   for (subblocks = BLOCK_SUBBLOCKS (block);
  3918.        subblocks; subblocks = BLOCK_CHAIN (subblocks))
  3919.     n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
  3920.  
  3921.   return n_blocks;
  3922. }
  3923.  
  3924. /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
  3925.    and initialize static variables for generating RTL for the statements
  3926.    of the function.  */
  3927.  
  3928. void
  3929. init_function_start (subr, filename, line)
  3930.      tree subr;
  3931.      char *filename;
  3932.      int line;
  3933. {
  3934.   char *junk;
  3935.  
  3936.   init_stmt_for_function ();
  3937.  
  3938.   cse_not_expected = ! optimize;
  3939.  
  3940.   /* Caller save not needed yet.  */
  3941.   caller_save_needed = 0;
  3942.  
  3943.   /* No stack slots have been made yet.  */
  3944.   stack_slot_list = 0;
  3945.  
  3946.   /* There is no stack slot for handling nonlocal gotos.  */
  3947.   nonlocal_goto_handler_slot = 0;
  3948.   nonlocal_goto_stack_level = 0;
  3949.  
  3950.   /* No labels have been declared for nonlocal use.  */
  3951.   nonlocal_labels = 0;
  3952.  
  3953.   /* No function calls so far in this function.  */
  3954.   function_call_count = 0;
  3955.  
  3956.   /* No parm regs have been allocated.
  3957.      (This is important for output_inline_function.)  */
  3958.   max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
  3959.  
  3960.   /* Initialize the RTL mechanism.  */
  3961.   init_emit ();
  3962.  
  3963.   /* Initialize the queue of pending postincrement and postdecrements,
  3964.      and some other info in expr.c.  */
  3965.   init_expr ();
  3966.  
  3967.   /* We haven't done register allocation yet.  */
  3968.   reg_renumber = 0;
  3969.  
  3970.   init_const_rtx_hash_table ();
  3971.  
  3972.   current_function_name = (*decl_printable_name) (subr, &junk);
  3973.  
  3974.   /* Nonzero if this is a nested function that uses a static chain.  */
  3975.  
  3976.   current_function_needs_context
  3977.     = (decl_function_context (current_function_decl) != 0);
  3978.  
  3979.   /* Set if a call to setjmp is seen.  */
  3980.   current_function_calls_setjmp = 0;
  3981.  
  3982.   /* Set if a call to longjmp is seen.  */
  3983.   current_function_calls_longjmp = 0;
  3984.  
  3985.   current_function_calls_alloca = 0;
  3986.   current_function_has_nonlocal_label = 0;
  3987.   current_function_contains_functions = 0;
  3988.  
  3989.   current_function_returns_pcc_struct = 0;
  3990.   current_function_returns_struct = 0;
  3991.   current_function_epilogue_delay_list = 0;
  3992.   current_function_uses_const_pool = 0;
  3993.   current_function_uses_pic_offset_table = 0;
  3994.  
  3995.   /* We have not yet needed to make a label to jump to for tail-recursion.  */
  3996.   tail_recursion_label = 0;
  3997.  
  3998.   /* We haven't had a need to make a save area for ap yet.  */
  3999.  
  4000.   arg_pointer_save_area = 0;
  4001.  
  4002.   /* No stack slots allocated yet.  */
  4003.   frame_offset = 0;
  4004.  
  4005.   /* No SAVE_EXPRs in this function yet.  */
  4006.   save_expr_regs = 0;
  4007.  
  4008.   /* No RTL_EXPRs in this function yet.  */
  4009.   rtl_expr_chain = 0;
  4010.  
  4011.   /* We have not allocated any temporaries yet.  */
  4012.   temp_slots = 0;
  4013.   temp_slot_level = 0;
  4014.  
  4015.   /* Within function body, compute a type's size as soon it is laid out.  */
  4016.   immediate_size_expand++;
  4017.  
  4018.   init_pending_stack_adjust ();
  4019.   inhibit_defer_pop = 0;
  4020.  
  4021.   current_function_outgoing_args_size = 0;
  4022.  
  4023.   /* Initialize the insn lengths.  */
  4024.   init_insn_lengths ();
  4025.  
  4026.   /* Prevent ever trying to delete the first instruction of a function.
  4027.      Also tell final how to output a linenum before the function prologue.  */
  4028.   emit_line_note (filename, line);
  4029.  
  4030.   /* Make sure first insn is a note even if we don't want linenums.
  4031.      This makes sure the first insn will never be deleted.
  4032.      Also, final expects a note to appear there.  */
  4033.   emit_note (NULL_PTR, NOTE_INSN_DELETED);
  4034.  
  4035.   /* Set flags used by final.c.  */
  4036.   if (aggregate_value_p (DECL_RESULT (subr)))
  4037.     {
  4038. #ifdef PCC_STATIC_STRUCT_RETURN
  4039.       if (flag_pcc_struct_return)
  4040.     current_function_returns_pcc_struct = 1;
  4041.       else
  4042. #endif
  4043.     current_function_returns_struct = 1;
  4044.     }
  4045.  
  4046.   /* Warn if this value is an aggregate type,
  4047.      regardless of which calling convention we are using for it.  */
  4048.   if (warn_aggregate_return
  4049.       && (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == RECORD_TYPE
  4050.       || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == UNION_TYPE
  4051.       || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == ARRAY_TYPE))
  4052.     warning ("function returns an aggregate");
  4053.  
  4054.   current_function_returns_pointer
  4055.     = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
  4056.  
  4057.   /* Indicate that we need to distinguish between the return value of the
  4058.      present function and the return value of a function being called.  */
  4059.   rtx_equal_function_value_matters = 1;
  4060.  
  4061.   /* Indicate that we have not instantiated virtual registers yet.  */
  4062.   virtuals_instantiated = 0;
  4063.  
  4064.   /* Indicate we have no need of a frame pointer yet.  */
  4065.   frame_pointer_needed = 0;
  4066.  
  4067.   /* By default assume not varargs.  */
  4068.   current_function_varargs = 0;
  4069.  
  4070.   current_function_call_convention = NULL;
  4071.  
  4072.   /* Maybe indicate that this function follows a Pascal calling convention.
  4073.      Only do this if Apple extensions are on. */
  4074.   current_function_is_pascal
  4075.     = flag_apple
  4076.       && (TREE_PASCAL (subr)
  4077.           || (TREE_TYPE (subr) != NULL
  4078.               && TYPE_CALL_CONVENTION (TREE_TYPE (subr)) != NULL
  4079.               && TYPE_CALL_CONVENTION_PASCAL (TREE_TYPE (subr))));
  4080. }
  4081.  
  4082. /* Indicate that the current function uses extra args
  4083.    not explicitly mentioned in the argument list in any fashion.  */
  4084.  
  4085. void
  4086. mark_varargs ()
  4087. {
  4088.   current_function_varargs = 1;
  4089. }
  4090.  
  4091. /* Expand a call to __main at the beginning of a possible main function.  */
  4092.  
  4093. void
  4094. expand_main_function ()
  4095. {
  4096. #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
  4097.   emit_library_call (gen_rtx (SYMBOL_REF, TPmode, "__main"), 0,
  4098.              VOIDmode, 0);
  4099. #endif /* not INIT_SECTION_ASM_OP or INVOKE__main */
  4100. }
  4101.  
  4102. /* Start the RTL for a new function, and set variables used for
  4103.    emitting RTL.
  4104.    SUBR is the FUNCTION_DECL node.
  4105.    PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
  4106.    the function's parameters, which must be run at any return statement.  */
  4107.  
  4108. void
  4109. expand_function_start (subr, parms_have_cleanups)
  4110.      tree subr;
  4111.      int parms_have_cleanups;
  4112. {
  4113.   register int i;
  4114.   tree tem;
  4115.   rtx last_ptr;
  4116.  
  4117.   /* Make sure volatile mem refs aren't considered
  4118.      valid operands of arithmetic insns.  */
  4119.   init_recog_no_volatile ();
  4120.  
  4121.   /* If function gets a static chain arg, store it in the stack frame.
  4122.      Do this first, so it gets the first stack slot offset.  */
  4123.   if (current_function_needs_context)
  4124.     {
  4125.       last_ptr = assign_stack_local (DPmode, GET_MODE_SIZE (DPmode), 0);
  4126.       emit_move_insn (last_ptr, static_chain_incoming_rtx);
  4127.     }
  4128.  
  4129.   /* If the parameters of this function need cleaning up, get a label
  4130.      for the beginning of the code which executes those cleanups.  This must
  4131.      be done before doing anything with return_label.  */
  4132.   if (parms_have_cleanups)
  4133.     cleanup_label = gen_label_rtx ();
  4134.   else
  4135.     cleanup_label = 0;
  4136.  
  4137.   /* Make the label for return statements to jump to, if this machine
  4138.      does not have a one-instruction return and uses an epilogue,
  4139.      or if it returns a structure, or if it has parm cleanups.  */
  4140. #ifdef HAVE_return
  4141.   if (cleanup_label == 0 && HAVE_return
  4142.       && ! current_function_returns_pcc_struct
  4143.       && ! (current_function_returns_struct && ! optimize))
  4144.     return_label = 0;
  4145.   else
  4146.     return_label = gen_label_rtx ();
  4147. #else
  4148.   return_label = gen_label_rtx ();
  4149. #endif
  4150.  
  4151.   /* Initialize rtx used to return the value.  */
  4152.   /* Do this before assign_parms so that we copy the struct value address
  4153.      before any library calls that assign parms might generate.  */
  4154.  
  4155.   /* Decide whether to return the value in memory or in a register.  */
  4156.   if (aggregate_value_p (DECL_RESULT (subr)))
  4157.     {
  4158.       /* Returning something that won't go in a register.  */
  4159.       register rtx value_address;
  4160.  
  4161. #ifdef PCC_STATIC_STRUCT_RETURN
  4162.       if (current_function_returns_pcc_struct)
  4163.     {
  4164.       int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
  4165.       value_address = assemble_static_space (size);
  4166.     }
  4167.       else
  4168. #endif
  4169.     {
  4170.       /* Expect to be passed the address of a place to store the value.
  4171.          If it is passed as an argument, assign_parms will take care of
  4172.          it.  */
  4173.       if (struct_value_incoming_rtx)
  4174.         {
  4175.           value_address = gen_reg_rtx (DPmode);
  4176.           emit_move_insn (value_address, struct_value_incoming_rtx);
  4177.         }
  4178.     }
  4179.       if (value_address)
  4180.     DECL_RTL (DECL_RESULT (subr))
  4181.       = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
  4182.              value_address);
  4183.     }
  4184.   else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
  4185.     /* If return mode is void, this decl rtl should not be used.  */
  4186.     DECL_RTL (DECL_RESULT (subr)) = 0;
  4187.   else if (parms_have_cleanups)
  4188.     {
  4189.       /* If function will end with cleanup code for parms,
  4190.      compute the return values into a pseudo reg,
  4191.      which we will copy into the true return register
  4192.      after the cleanups are done.  */
  4193.  
  4194.       enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
  4195. #ifdef PROMOTE_FUNCTION_RETURN
  4196.       tree type = TREE_TYPE (DECL_RESULT (subr));
  4197.       int unsignedp = TREE_UNSIGNED (type);
  4198.  
  4199.       if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE
  4200.       || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE
  4201.       || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE
  4202.       || TREE_CODE (type) == OFFSET_TYPE)
  4203.     {
  4204.       PROMOTE_MODE (mode, unsignedp, type);
  4205.     }
  4206. #endif
  4207.  
  4208.       DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
  4209.     }
  4210.   else
  4211.     /* Scalar, returned in a register.  */
  4212.     {
  4213. #ifdef FUNCTION_OUTGOING_VALUE
  4214.       DECL_RTL (DECL_RESULT (subr))
  4215.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4216. #else
  4217.       DECL_RTL (DECL_RESULT (subr))
  4218.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4219. #endif
  4220.  
  4221.       /* Mark this reg as the function's return value.  */
  4222.       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
  4223.     {
  4224.       REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
  4225.       /* Needed because we may need to move this to memory
  4226.          in case it's a named return value whose address is taken.  */
  4227.       DECL_REGISTER (DECL_RESULT (subr)) = 1;
  4228.     }
  4229.     }
  4230.  
  4231.   /* Initialize rtx for parameters and local variables.
  4232.      In some cases this requires emitting insns.  */
  4233.  
  4234.   assign_parms (subr, 0);
  4235.  
  4236.   /* The following was moved from init_function_start.
  4237.      The move is supposed to make sdb output more accurate.  */
  4238.   /* Indicate the beginning of the function body,
  4239.      as opposed to parm setup.  */
  4240.   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
  4241.  
  4242.   /* If we're doing a pascal-declared function, patch the location of the
  4243.      return result, now that we know its location.  The rtx we're patching
  4244.      was produced by FUNCTION_OUTGOING_VALUE; we're replacing the "12345"
  4245.      that it generated as a placeholder. */
  4246.   if (current_function_is_pascal &&
  4247.       ! aggregate_value_p (DECL_RESULT (subr)) &&
  4248.       ! (DECL_MODE (DECL_RESULT (subr)) == VOIDmode) &&
  4249.       ! parms_have_cleanups)
  4250.     XINT (XEXP (XEXP (DECL_RTL (DECL_RESULT (subr)), 0), 1), 0) =
  4251.       current_function_args_size + 8;
  4252.  
  4253.   /* If doing stupid allocation, mark parms as born here.  */
  4254.  
  4255.   if (GET_CODE (get_last_insn ()) != NOTE)
  4256.     emit_note (NULL_PTR, NOTE_INSN_DELETED);
  4257.   parm_birth_insn = get_last_insn ();
  4258.  
  4259.   if (obey_regdecls)
  4260.     {
  4261.       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
  4262.     use_variable (regno_reg_rtx[i]);
  4263.  
  4264.       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
  4265.     use_variable (current_function_internal_arg_pointer);
  4266.     }
  4267.  
  4268.   /* Fetch static chain values for containing functions.  */
  4269.   tem = decl_function_context (current_function_decl);
  4270.   /* If not doing stupid register allocation, then start off with the static
  4271.      chain pointer in a pseudo register.  Otherwise, we use the stack
  4272.      address that was generated above.  */
  4273.   if (tem && ! obey_regdecls)
  4274.     last_ptr = copy_to_reg (static_chain_incoming_rtx);
  4275.   context_display = 0;
  4276.   while (tem)
  4277.     {
  4278.       tree rtlexp = make_node (RTL_EXPR);
  4279.  
  4280.       RTL_EXPR_RTL (rtlexp) = last_ptr;
  4281.       context_display = tree_cons (tem, rtlexp, context_display);
  4282.       tem = decl_function_context (tem);
  4283.       if (tem == 0)
  4284.     break;
  4285.       /* Chain thru stack frames, assuming pointer to next lexical frame
  4286.      is found at the place we always store it.  */
  4287. #ifdef FRAME_GROWS_DOWNWARD
  4288.       last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (DPmode));
  4289.       last_ptr = copy_to_reg (gen_rtx (MEM, DPmode,
  4290.                        memory_address (DPmode, last_ptr)));
  4291. #endif
  4292.     }
  4293.  
  4294.   /* After the display initializations is where the tail-recursion label
  4295.      should go, if we end up needing one.   Ensure we have a NOTE here
  4296.      since some things (like trampolines) get placed before this.  */
  4297.   tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
  4298.  
  4299.   /* Evaluate now the sizes of any types declared among the arguments.  */
  4300.   for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
  4301.     expand_expr (TREE_VALUE (tem), NULL_RTX, VOIDmode, 0);
  4302.  
  4303.   /* Make sure there is a line number after the function entry setup code.  */
  4304.   force_next_line_note ();
  4305. }
  4306.  
  4307. /* Generate RTL for the end of the current function.
  4308.    FILENAME and LINE are the current position in the source file.  */
  4309.  
  4310. /* It is up to language-specific callers to do cleanups for parameters.  */
  4311.  
  4312. void
  4313. expand_function_end (filename, line)
  4314.      char *filename;
  4315.      int line;
  4316. {
  4317.   register int i;
  4318.   tree link;
  4319.  
  4320.   static rtx initial_trampoline;
  4321.  
  4322. #ifdef NON_SAVING_SETJMP
  4323.   /* Don't put any variables in registers if we call setjmp
  4324.      on a machine that fails to restore the registers.  */
  4325.   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
  4326.     {
  4327.       setjmp_protect (DECL_INITIAL (current_function_decl));
  4328.       setjmp_protect_args ();
  4329.     }
  4330. #endif
  4331.  
  4332.   /* Save the argument pointer if a save area was made for it.  */
  4333.   if (arg_pointer_save_area)
  4334.     {
  4335.       rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
  4336.       emit_insn_before (x, tail_recursion_reentry);
  4337.     }
  4338.  
  4339.   /* Initialize any trampolines required by this function.  */
  4340.   for (link = trampoline_list; link; link = TREE_CHAIN (link))
  4341.     {
  4342.       tree function = TREE_PURPOSE (link);
  4343.       rtx context = lookup_static_chain (function);
  4344.       rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
  4345.       rtx seq;
  4346.  
  4347.       /* First make sure this compilation has a template for
  4348.      initializing trampolines.  */
  4349.       if (initial_trampoline == 0)
  4350.     {
  4351.       end_temporary_allocation ();
  4352.       initial_trampoline
  4353.         = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
  4354.       resume_temporary_allocation ();
  4355.     }
  4356.  
  4357.       /* Generate insns to initialize the trampoline.  */
  4358.       start_sequence ();
  4359.       tramp = change_address (initial_trampoline, BLKmode,
  4360.                   round_trampoline_addr (XEXP (tramp, 0)));
  4361.       emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
  4362.                FUNCTION_BOUNDARY / BITS_PER_UNIT);
  4363.       INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
  4364.                  XEXP (DECL_RTL (function), 0), context);
  4365.       seq = get_insns ();
  4366.       end_sequence ();
  4367.  
  4368.       /* Put those insns at entry to the containing function (this one).  */
  4369.       emit_insns_before (seq, tail_recursion_reentry);
  4370.     }
  4371.   /* Clear the trampoline_list for the next function.  */
  4372.   trampoline_list = 0;
  4373.  
  4374. #if 0  /* I think unused parms are legitimate enough.  */
  4375.   /* Warn about unused parms.  */
  4376.   if (warn_unused)
  4377.     {
  4378.       rtx decl;
  4379.  
  4380.       for (decl = DECL_ARGUMENTS (current_function_decl);
  4381.        decl; decl = TREE_CHAIN (decl))
  4382.     if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
  4383.       warning_with_decl (decl, "unused parameter `%s'");
  4384.     }
  4385. #endif
  4386.  
  4387.   /* Delete handlers for nonlocal gotos if nothing uses them.  */
  4388.   if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
  4389.     delete_handlers ();
  4390.  
  4391.   /* End any sequences that failed to be closed due to syntax errors.  */
  4392.   while (in_sequence_p ())
  4393.     end_sequence ();
  4394.  
  4395.   /* Outside function body, can't compute type's actual size
  4396.      until next function's body starts.  */
  4397.   immediate_size_expand--;
  4398.  
  4399.   /* If doing stupid register allocation,
  4400.      mark register parms as dying here.  */
  4401.  
  4402.   if (obey_regdecls)
  4403.     {
  4404.       rtx tem;
  4405.       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
  4406.     use_variable (regno_reg_rtx[i]);
  4407.  
  4408.       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
  4409.  
  4410.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  4411.     {
  4412.       use_variable (XEXP (tem, 0));
  4413.       use_variable_after (XEXP (tem, 0), parm_birth_insn);
  4414.     }
  4415.  
  4416.       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
  4417.     use_variable (current_function_internal_arg_pointer);
  4418.     }
  4419.  
  4420.   clear_pending_stack_adjust ();
  4421.   do_pending_stack_adjust ();
  4422.  
  4423.   /* Mark the end of the function body.
  4424.      If control reaches this insn, the function can drop through
  4425.      without returning a value.  */
  4426.   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
  4427.  
  4428.   /* Output a linenumber for the end of the function.
  4429.      SDB depends on this.  */
  4430.   emit_line_note_force (filename, line);
  4431.  
  4432.   /* Output the label for the actual return from the function,
  4433.      if one is expected.  This happens either because a function epilogue
  4434.      is used instead of a return instruction, or because a return was done
  4435.      with a goto in order to run local cleanups, or because of pcc-style
  4436.      structure returning.  */
  4437.  
  4438.   if (return_label)
  4439.     emit_label (return_label);
  4440.  
  4441.   /* If we had calls to alloca, and this machine needs
  4442.      an accurate stack pointer to exit the function,
  4443.      insert some code to save and restore the stack pointer.  */
  4444. #ifdef EXIT_IGNORE_STACK
  4445.   if (! EXIT_IGNORE_STACK)
  4446. #endif
  4447.     if (current_function_calls_alloca)
  4448.       {
  4449.     rtx tem = 0;
  4450.  
  4451.     emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
  4452.     emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
  4453.       }
  4454.  
  4455.   /* If scalar return value was computed in a pseudo-reg,
  4456.      copy that to the hard return register.  */
  4457.   if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
  4458.       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
  4459.       && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
  4460.       >= FIRST_PSEUDO_REGISTER))
  4461.     {
  4462.       rtx real_decl_result;
  4463.  
  4464. #ifdef FUNCTION_OUTGOING_VALUE
  4465.       real_decl_result
  4466.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  4467.                    current_function_decl);
  4468. #else
  4469.       real_decl_result
  4470.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  4471.               current_function_decl);
  4472. #endif
  4473.       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
  4474.       emit_move_insn (real_decl_result,
  4475.               DECL_RTL (DECL_RESULT (current_function_decl)));
  4476.       emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
  4477.     }
  4478.  
  4479.   /* If returning a structure, arrange to return the address of the value
  4480.      in a place where debuggers expect to find it.
  4481.  
  4482.      If returning a structure PCC style,
  4483.      the caller also depends on this value.
  4484.      And current_function_returns_pcc_struct is not necessarily set.  */
  4485.   if (current_function_returns_struct
  4486.       || current_function_returns_pcc_struct)
  4487.     {
  4488.       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
  4489.       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  4490. #ifdef FUNCTION_OUTGOING_VALUE
  4491.       rtx outgoing
  4492.     = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
  4493.                    current_function_decl);
  4494. #else
  4495.       rtx outgoing
  4496.     = FUNCTION_VALUE (build_pointer_type (type),
  4497.               current_function_decl);
  4498. #endif
  4499.  
  4500.       /* Mark this as a function return value so integrate will delete the
  4501.      assignment and USE below when inlining this function.  */
  4502.       REG_FUNCTION_VALUE_P (outgoing) = 1;
  4503.  
  4504.       emit_move_insn (outgoing, value_address);
  4505.       use_variable (outgoing);
  4506.     }
  4507.  
  4508.   /* Output a return insn if we are using one.
  4509.      Otherwise, let the rtl chain end here, to drop through
  4510.      into the epilogue.  */
  4511.  
  4512. #ifdef HAVE_return
  4513.   if (HAVE_return)
  4514.     {
  4515.       emit_jump_insn (gen_return ());
  4516.       emit_barrier ();
  4517.     }
  4518. #endif
  4519.  
  4520.   /* Fix up any gotos that jumped out to the outermost
  4521.      binding level of the function.
  4522.      Must follow emitting RETURN_LABEL.  */
  4523.  
  4524.   /* If you have any cleanups to do at this point,
  4525.      and they need to create temporary variables,
  4526.      then you will lose.  */
  4527.   fixup_gotos (NULL_PTR, NULL_RTX, NULL_TREE, get_insns (), 0);
  4528. }
  4529.  
  4530. /* These arrays record the INSN_UIDs of the prologue and epilogue insns.  */
  4531.  
  4532. static int *prologue;
  4533. static int *epilogue;
  4534.  
  4535. /* Create an array that records the INSN_UIDs of INSNS (either a sequence
  4536.    or a single insn).  */
  4537.  
  4538. static int *
  4539. record_insns (insns)
  4540.      rtx insns;
  4541. {
  4542.   int *vec;
  4543.  
  4544.   if (GET_CODE (insns) == SEQUENCE)
  4545.     {
  4546.       int len = XVECLEN (insns, 0);
  4547.       vec = (int *) oballoc ((len + 1) * sizeof (int));
  4548.       vec[len] = 0;
  4549.       while (--len >= 0)
  4550.     vec[len] = INSN_UID (XVECEXP (insns, 0, len));
  4551.     }
  4552.   else
  4553.     {
  4554.       vec = (int *) oballoc (2 * sizeof (int));
  4555.       vec[0] = INSN_UID (insns);
  4556.       vec[1] = 0;
  4557.     }
  4558.   return vec;
  4559. }
  4560.  
  4561. /* Determine how many INSN_UIDs in VEC are part of INSN.  */
  4562.  
  4563. static int
  4564. contains (insn, vec)
  4565.      rtx insn;
  4566.      int *vec;
  4567. {
  4568.   register int i, j;
  4569.  
  4570.   if (GET_CODE (insn) == INSN
  4571.       && GET_CODE (PATTERN (insn)) == SEQUENCE)
  4572.     {
  4573.       int count = 0;
  4574.       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
  4575.     for (j = 0; vec[j]; j++)
  4576.       if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
  4577.         count++;
  4578.       return count;
  4579.     }
  4580.   else
  4581.     {
  4582.       for (j = 0; vec[j]; j++)
  4583.     if (INSN_UID (insn) == vec[j])
  4584.       return 1;
  4585.     }
  4586.   return 0;
  4587. }
  4588.  
  4589. /* Generate the prologe and epilogue RTL if the machine supports it.  Thread
  4590.    this into place with notes indicating where the prologue ends and where
  4591.    the epilogue begins.  Update the basic block information when possible.  */
  4592.  
  4593. void
  4594. thread_prologue_and_epilogue_insns (f)
  4595.      rtx f;
  4596. {
  4597. #ifdef HAVE_prologue
  4598.   if (HAVE_prologue)
  4599.     {
  4600.       rtx head, seq, insn;
  4601.  
  4602.       /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
  4603.      prologue insns and a NOTE_INSN_PROLOGUE_END.  */
  4604.       emit_note_after (NOTE_INSN_PROLOGUE_END, f);
  4605.       seq = gen_prologue ();
  4606.       head = emit_insn_after (seq, f);
  4607.  
  4608.       /* Include the new prologue insns in the first block.  Ignore them
  4609.      if they form a basic block unto themselves.  */
  4610.       if (basic_block_head && n_basic_blocks
  4611.       && GET_CODE (basic_block_head[0]) != CODE_LABEL)
  4612.     basic_block_head[0] = NEXT_INSN (f);
  4613.  
  4614.       /* Retain a map of the prologue insns.  */
  4615.       prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
  4616.     }
  4617.   else
  4618. #endif
  4619.     prologue = 0;
  4620.  
  4621. #ifdef HAVE_epilogue
  4622.   if (HAVE_epilogue)
  4623.     {
  4624.       rtx insn = get_last_insn ();
  4625.       rtx prev = prev_nonnote_insn (insn);
  4626.  
  4627.       /* If we end with a BARRIER, we don't need an epilogue.  */
  4628.       if (! (prev && GET_CODE (prev) == BARRIER))
  4629.     {
  4630.       rtx tail, seq;
  4631.  
  4632.       /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG,
  4633.          the epilogue insns (this must include the jump insn that
  4634.          returns), USE insns ad the end of a function, and a BARRIER.  */
  4635.  
  4636.       emit_barrier_after (insn);
  4637.  
  4638.       /* Place the epilogue before the USE insns at the end of a
  4639.          function.  */
  4640.       while (prev
  4641.          && GET_CODE (prev) == INSN
  4642.          && GET_CODE (PATTERN (prev)) == USE)
  4643.         {
  4644.           insn = PREV_INSN (prev);
  4645.           prev = prev_nonnote_insn (prev);
  4646.         }
  4647.  
  4648.       seq = gen_epilogue ();
  4649.       tail = emit_jump_insn_after (seq, insn);
  4650.       emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
  4651.  
  4652.       /* Include the new epilogue insns in the last block.  Ignore
  4653.          them if they form a basic block unto themselves.  */
  4654.       if (basic_block_end && n_basic_blocks
  4655.           && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
  4656.         basic_block_end[n_basic_blocks - 1] = tail;
  4657.  
  4658.       /* Retain a map of the epilogue insns.  */
  4659.       epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
  4660.       return;
  4661.     }
  4662.     }
  4663. #endif
  4664.   epilogue = 0;
  4665. }
  4666.  
  4667. /* Reposition the prologue-end and epilogue-begin notes after instruction
  4668.    scheduling and delayed branch scheduling.  */
  4669.  
  4670. void
  4671. reposition_prologue_and_epilogue_notes (f)
  4672.      rtx f;
  4673. {
  4674. #if defined (HAVE_prologue) || defined (HAVE_epilogue)
  4675.   /* Reposition the prologue and epilogue notes.  */
  4676.   if (n_basic_blocks)
  4677.     {
  4678.       rtx next, prev;
  4679.       int len;
  4680.  
  4681.       if (prologue)
  4682.     {
  4683.       register rtx insn, note = 0;
  4684.  
  4685.       /* Scan from the beginning until we reach the last prologue insn.
  4686.          We apparently can't depend on basic_block_{head,end} after
  4687.          reorg has run.  */
  4688.       for (len = 0; prologue[len]; len++)
  4689.         ;
  4690.       for (insn = f; insn; insn = NEXT_INSN (insn))
  4691.         if (GET_CODE (insn) == NOTE)
  4692.           {
  4693.         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
  4694.           note = insn;
  4695.           }
  4696.         else if ((len -= contains (insn, prologue)) == 0)
  4697.           {
  4698.         /* Find the prologue-end note if we haven't already, and
  4699.            move it to just after the last prologue insn.  */
  4700.         if (note == 0)
  4701.           for (note = insn; note = NEXT_INSN (note);)
  4702.             if (GET_CODE (note) == NOTE
  4703.             && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
  4704.               break;
  4705.         next = NEXT_INSN (note);
  4706.         prev = PREV_INSN (note);
  4707.         if (prev)
  4708.           NEXT_INSN (prev) = next;
  4709.         if (next)
  4710.           PREV_INSN (next) = prev;
  4711.         add_insn_after (note, insn);
  4712.         break;
  4713.           }
  4714.     }
  4715.  
  4716.       if (epilogue)
  4717.     {
  4718.       register rtx insn, note = 0;
  4719.  
  4720.       /* Scan from the end until we reach the first epilogue insn.
  4721.          We apparently can't depend on basic_block_{head,end} after
  4722.          reorg has run.  */
  4723.       for (len = 0; epilogue[len]; len++)
  4724.         ;
  4725.       for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
  4726.         if (GET_CODE (insn) == NOTE)
  4727.           {
  4728.         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
  4729.           note = insn;
  4730.           }
  4731.         else if ((len -= contains (insn, epilogue)) == 0)
  4732.           {
  4733.         /* Find the epilogue-begin note if we haven't already, and
  4734.            move it to just before the first epilogue insn.  */
  4735.         if (note == 0)
  4736.           for (note = insn; note = PREV_INSN (note);)
  4737.             if (GET_CODE (note) == NOTE
  4738.             && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
  4739.               break;
  4740.         next = NEXT_INSN (note);
  4741.         prev = PREV_INSN (note);
  4742.         if (prev)
  4743.           NEXT_INSN (prev) = next;
  4744.         if (next)
  4745.           PREV_INSN (next) = prev;
  4746.         add_insn_after (note, PREV_INSN (insn));
  4747.         break;
  4748.           }
  4749.     }
  4750.     }
  4751. #endif /* HAVE_prologue or HAVE_epilogue */
  4752. }
  4753.